Exemplo n.º 1
0
 public void Ignore_frozen_bit()
 {
     SigoAssert.Equal(
         Hash(Sigo.Create(0, "x", 1)),
         Hash(Sigo.Create(0, "x", 1).Freeze())
         );
 }
Exemplo n.º 2
0
        public void If_sigosAreEqual_then_hashsAreEqual()
        {
            var sigos = new List <ISigo> {
                Sigo.From("a"),
                Sigo.From("a"),
                Sigo.From("b"),
                Sigo.Create(0),
                Sigo.Create(3),
                Sigo.Create(1, "x", "1", "y", "2").Freeze(),
                Sigo.Create(1, "y", "2", "x", "1"),
                Sigo.Create(1, "y", "2", "x", "2"),
                Sigo.Create(1, "diff", "2", "x", "1")
            };

            foreach (var a in sigos)
            {
                foreach (var b in sigos)
                {
                    if (a.Equals(b))
                    {
                        // THIS IS A MUST
                        SigoAssert.Equal(Hash(a), Hash(b));
                    }
                    else
                    {
                        // THIS IS A SHOULD
                        SigoAssert.NotEqual(Hash(a), Hash(b));
                    }
                }
            }
        }
Exemplo n.º 3
0
 public void AreFrozen()
 {
     for (var i = 0; i < 8; i++)
     {
         var sigo = Sigo.Create(i);
         SigoAssert.Equal(Bits.F + i, sigo.Flags);
     }
 }
Exemplo n.º 4
0
        public void AllowPathDuplicated_overwritingChild()
        {
            var user = Sigo.Create(3,
                                   "user/id", 100.0,
                                   "user/id", 200.0,
                                   "user/id", 200.0);

            SigoAssert.Equal(200.0, user.Get1("user").Get1("id").Data);
        }
Exemplo n.º 5
0
        public void Trees_compare_theirChildren()
        {
            var a = Sigo.Create(0, "k", "v+");
            var b = Sigo.Create(0, "k", "v+");
            var c = Sigo.Create(0, "k", "v-");

            SigoAssert.Equal(a, b);
            SigoAssert.NotEqual(b, c);
        }
Exemplo n.º 6
0
        public void Trees_dontCompare_theirNeutron()
        {
            var a = Sigo.Create(3, "k", "v");
            var b = Sigo.Create(3, "k", "v").Freeze();

            SigoAssert.NotEqual(a.Flags, b.Flags);

            SigoAssert.Equal(a, b);
        }
Exemplo n.º 7
0
        public void Trees_dontCompare_theirChildOder()
        {
            var a = Sigo.Create(3, "k1", "v1", "k2", "v2");
            var b = Sigo.Create(3, "k2", "v2", "k1", "v1");

            SigoAssert.NotEqual(a.Keys.First(), b.Keys.First());

            SigoAssert.Equal(a, b);
        }
Exemplo n.º 8
0
        public void Trees_compare_deeply()
        {
            var a1 = Sigo.Create(0, "a/b/c/d", "v+");
            var a2 = Sigo.Create(0, "a/b/c/d", "v+");
            var b1 = Sigo.Create(0, "a/b/c/d", "v-");

            SigoAssert.Equal(a1, a2);
            SigoAssert.NotEqual(a1, b1);
        }
Exemplo n.º 9
0
        public void ChangeFlagsOnly()
        {
            var s0 = e0.Set1("k", e3).Freeze();

            // change parent proton by adding a child with L effect
            var s1 = s0.Set1("k2", e4).Freeze();

            SigoAssert.Equal(e3, s1.Get1("k"));
            SigoAssert.Equal(Bits.LM, s1.Flags & Bits.LMR);
        }
Exemplo n.º 10
0
        public void AddNewChild()
        {
            var s0 = Sigo.Create(0);
            var s1 = s0.Set1("k1", v1).Freeze();
            var s2 = s1.Set1("k2", v2).Freeze();

            SigoAssert.Equal(v1, s2.Get1("k1"));
            SigoAssert.Equal(v2, s2.Get1("k2"));
            SigoAssert.Equal(256 * 2 + 16 + 6, s2.Flags);
        }
Exemplo n.º 11
0
        public void AllowPath()
        {
            var user = Sigo.Create(3,
                                   "name/first", "Phat",
                                   "name/last", "Dam",
                                   "male", true);

            SigoAssert.Equal("Phat", user.Get1("name").Get1("first").Data);
            SigoAssert.Equal("Dam", user.Get1("name").Get1("last").Data);
            SigoAssert.Equal(true, user.Get1("male").Data);
        }
Exemplo n.º 12
0
        public void AddNewChild()
        {
            var s = Sigo.Create(0);

            s = s.Set1("k1", v1);
            s = s.Set1("k2", v2);

            SigoAssert.Equal(v1, s.Get1("k1"));
            SigoAssert.Equal(v2, s.Get1("k2"));
            SigoAssert.Equal(256 * 2 + 6, s.Flags);
        }
Exemplo n.º 13
0
 public void TODO_strict(bool allow, string path)
 {
     if (allow)
     {
         SigoAssert.Equal("v", Sigo.Create(3, path, "v").Get(path).Data);
     }
     else
     {
         SigoAssert.ThrowsAny <Exception>(() => Sigo.Create(3, path, "v"));
     }
 }
Exemplo n.º 14
0
        public void ChangeAnExistingChild()
        {
            var s0 = Sigo.Create(0);
            // add
            var s1 = s0.Set1("k", v1).Freeze();

            // set again
            var s2 = s1.Set1("k", v2).Freeze();

            SigoAssert.Equal(v2, s2.Get1("k"));
            SigoAssert.Equal(256 + 16 + 6, s2.Flags);
        }
Exemplo n.º 15
0
        public void See_createTests()
        {
            var user = Sigo.Create(1);

            user = user.Set("name/first", Sigo.From("Phat"));
            user = user.Set("name/last", Sigo.From("Dam"));
            user = user.Set("male", Sigo.From(true));

            SigoAssert.Equal("Phat", user.Get1("name").Get1("first").Data);
            SigoAssert.Equal("Dam", user.Get1("name").Get1("last").Data);
            SigoAssert.Equal(true, user.Get1("male").Data);
        }
Exemplo n.º 16
0
        public void Overrided_getHashCode()
        {
            var list = new List <ISigo> {
                Sigo.From("a"),
                Sigo.Create(7),
                Sigo.Create(3, "k", "a")
            };

            foreach (var a in list)
            {
                SigoAssert.Equal(Sigo.GetHashCode(a), a.GetHashCode());
            }
        }
Exemplo n.º 17
0
        public void ChangeAnExistingChild()
        {
            var s = e0;

            // add
            s = s.Set1("k", v1);

            // set again
            s = s.Set1("k", v2);

            SigoAssert.Equal(v2, s.Get1("k"));
            SigoAssert.Equal(256 + 6, s.Flags);
        }
Exemplo n.º 18
0
        public void Numbers_are_convert_to_double()
        {
            var inputs = new object[] {
                (int)1,
                (long)1,
                (float)1,
                (double)1
            };

            foreach (var number in inputs)
            {
                var sigo = Sigo.From(number);

                SigoAssert.Equal(Convert.ToDouble(number), sigo.Data);
            }
        }
Exemplo n.º 19
0
        public void Return_leaf_if_input_is_scalar()
        {
            var inputs = new object[] {
                true, false,
                123.0,
                "",
                "abc"
            };

            foreach (var scalar in inputs)
            {
                var sigo = Sigo.From(scalar);

                SigoAssert.True(sigo.IsLeaf());
                SigoAssert.Equal(scalar, sigo.Data);
            }
        }
Exemplo n.º 20
0
        public void Convert_to_tree_if_input_is_enumerable()
        {
            var inputs = new object[] {
                new[] { "a", "b" },
                new List <string> {
                    "a", "b"
                }
            };

            foreach (var o in inputs)
            {
                var sigo = Sigo.From(o);

                SigoAssert.True(sigo.IsTree());
                SigoAssert.Equal("a", sigo.Get1("0").Data);
                SigoAssert.Equal("b", sigo.Get1("1").Data);
            }
        }
Exemplo n.º 21
0
        public void Overrided_equal_object()
        {
            var list = new List <ISigo> {
                Sigo.From("a"),
                Sigo.From("a"),
                Sigo.From("b"),
                Sigo.Create(3, "k", "a"),
                Sigo.Create(3, "k", "a"),
                Sigo.Create(3, "k", "b")
            };

            foreach (var a in list)
            {
                foreach (var b in list)
                {
                    SigoAssert.Equal(Sigo.Equals(a, b), a.Equals((object)b));
                }
            }
        }
Exemplo n.º 22
0
        public void RemoveAnExistingChild()
        {
            var s = e0;

            // add
            s = s.Set1("k1", v1);
            s = s.Set1("k2", v2);

            // remove k1
            s = s.Set1("k1", e0);
            SigoAssert.Equal(e0, s.Get1("k1"));
            SigoAssert.Equal(v2, s.Get1("k2"));
            SigoAssert.Equal(256 + 6, s.Flags);

            // remove k2
            s = s.Set1("k2", e4);
            SigoAssert.Equal(e0, s.Get1("k1"));
            SigoAssert.Equal(e0, s.Get1("k2"));
            SigoAssert.Equal(e6, s);
        }
Exemplo n.º 23
0
        public void RemoveAnExistingChild()
        {
            var s0 = Sigo.Create(0);
            // add
            var s1 = s0.Set1("k1", v1).Freeze();
            var s2 = s1.Set1("k2", v2).Freeze();

            // remove k1
            var s3 = s2.Set1("k1", e0).Freeze();

            SigoAssert.Equal(e0, s3.Get1("k1"));
            SigoAssert.Equal(v2, s3.Get1("k2"));
            SigoAssert.Equal(256 + 16 + 6, s3.Flags);

            // remove k2
            var s4 = s3.Set1("k2", e4).Freeze();

            SigoAssert.Equal(e0, s4.Get1("k1"));
            SigoAssert.Equal(e0, s4.Get1("k2"));
            SigoAssert.Equal(e6, s4);
        }
Exemplo n.º 24
0
        public void Convert_to_tree_if_input_is_dictionary()
        {
            var inputs = new object[] {
                new Hashtable()
                {
                    { "k", "v" }
                },
                new Dictionary <string, object>()
                {
                    { "k", "v" }
                }
            };

            foreach (var o in inputs)
            {
                var sigo = Sigo.From(o);

                SigoAssert.True(sigo.IsTree());
                SigoAssert.Equal("v", sigo.Get1("k").Data);
            }
        }
Exemplo n.º 25
0
        public void Return_default()
        {
            var sigos = new List <ISigo> {
                Sigo.From("v"),
                Sigo.Create(0),
                Sigo.Create(1),
                Sigo.Create(0).Set1("k", Sigo.From("v")),
                Sigo.Create(1).Set1("k", Sigo.From("v"))
            };

            foreach (var sigo in sigos)
            {
                if ((sigo.Flags & Bits.R) == Bits.R)
                {
                    SigoAssert.Equal(Sigo.Create(3), sigo.Get1("nonExists"));
                }
                else
                {
                    SigoAssert.Equal(Sigo.Create(0), sigo.Get1("nonExists"));
                }
            }
        }
Exemplo n.º 26
0
 public void Null_return_0()
 {
     SigoAssert.Equal(0, Hash(null));
 }
Exemplo n.º 27
0
 public void Leafs_compare_theirData()
 {
     SigoAssert.Equal(Sigo.From(10000), Sigo.From(10000));
     SigoAssert.Equal(Sigo.From(true), Sigo.From(true));
     SigoAssert.Equal(Sigo.From("abc"), Sigo.From("abc"));
 }
Exemplo n.º 28
0
        public void AllowPathFromObject(object key, string sameAs)
        {
            var sigo = Sigo.Create(3, key, "v");

            SigoAssert.Equal("v", sigo.Get1(sameAs).Data);
        }
Exemplo n.º 29
0
        public void AllowPathWithoutKeys_returnTheChild(string path)
        {
            var value = Sigo.From("child");

            SigoAssert.Equal(value, Sigo.Create(3, path, value));
        }
Exemplo n.º 30
0
        public void Return_the_child()
        {
            var sigo = Sigo.Create(0).Set1("k", Sigo.From("v"));

            SigoAssert.Equal("v", sigo.Get1("k").Data);
        }