Exemple #1
0
        public void Trees_compare_theirProton()
        {
            var a = Sigo.Create(3, "k", "v");
            var b = Sigo.Create(0, "k", "v");

            SigoAssert.NotEqual(a, b);
        }
Exemple #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));
                    }
                }
            }
        }
Exemple #3
0
 public void AreSingleton()
 {
     for (var i = 0; i < 8; i++)
     {
         SigoAssert.Same(Sigo.Create(i), Sigo.Create(i));
     }
 }
Exemple #4
0
 public void Ignore_frozen_bit()
 {
     SigoAssert.Equal(
         Hash(Sigo.Create(0, "x", 1)),
         Hash(Sigo.Create(0, "x", 1).Freeze())
         );
 }
Exemple #5
0
 public void AreFrozen()
 {
     for (var i = 0; i < 8; i++)
     {
         var sigo = Sigo.Create(i);
         SigoAssert.Equal(Bits.F + i, sigo.Flags);
     }
 }
Exemple #6
0
        public void Trees_only_compare_using_referenceEquals()
        {
            var tree1 = Sigo.Create(3).Set1("k", Sigo.From("v"));
            var tree2 = Sigo.Create(3).Set1("k", Sigo.From("v"));

            SigoAssert.True(Sigo.Same(tree1, tree1));

            SigoAssert.False(Sigo.Same(tree1, tree2));
        }
Exemple #7
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);
        }
Exemple #8
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);
        }
Exemple #9
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);
        }
Exemple #10
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);
        }
Exemple #11
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);
        }
Exemple #12
0
        public void Frozen_return_self()
        {
            var leaf = Sigo.From("leaf");
            var e3   = Sigo.Create(3);
            var tree = Sigo.Create(3, "k", "v").Freeze();

            SigoAssert.Same(leaf, leaf.Clone());
            SigoAssert.Same(e3, e3.Clone());
            SigoAssert.Same(tree, tree.Clone());
        }
Exemple #13
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);
        }
Exemple #14
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);
        }
Exemple #15
0
        public void Leafs_compare_data_using_equals()
        {
            var v1 = Sigo.From("v");
            var v2 = Sigo.From("v");
            var x1 = Sigo.From("x");

            SigoAssert.True(Sigo.Same(v1, v1));
            SigoAssert.True(Sigo.Same(v1, v2));

            SigoAssert.False(Sigo.Same(v1, x1));
        }
Exemple #16
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"));
     }
 }
Exemple #17
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);
        }
Exemple #18
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);
        }
Exemple #19
0
        public void Donot_createNewObject_ifNothingChange()
        {
            var v = Sigo.From("v");
            var s = e3.Set1("k", v).Freeze();

            SigoAssert.Same(s, s.Set1("k", v));
            SigoAssert.Same(s, s.Set1("k1", e3));
            SigoAssert.Same(s, s.Set1("k1", e7));

            // using Sigo.Same(), insteadOf referenceEquals
            SigoAssert.Same(s, s.Set1("k", Sigo.From("v")));
        }
Exemple #20
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);
        }
Exemple #21
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);
        }
Exemple #22
0
        public void Return_self()
        {
            var sigos = new[] { V, A, E[0] };
            var paths = new[] { null, "", "/" };

            foreach (var sigo in sigos)
            {
                foreach (var path in paths)
                {
                    SigoAssert.Same(sigo, sigo.Get(path));
                }
            }
        }
Exemple #23
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);
        }
Exemple #24
0
        public void NonEmptyTree_areNotFrozen_after_creating_or_changing()
        {
            // non empty tree are not frozen after creating
            SigoAssert.False(tree.IsFrozen());

            // not frozen after changing
            tree = tree.Freeze().Set1("v", Sigo.From("v+"));
            SigoAssert.False(tree.IsFrozen());

            // leafs and elements are frozen always frozen
            SigoAssert.True(leaf.IsFrozen());
            SigoAssert.True(e3.IsFrozen());
        }
Exemple #25
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());
            }
        }
Exemple #26
0
        public void Return_using_Get1()
        {
            var sigos = new[] { A, V, E[0] };
            var paths = new[] { "x", "/x/", "z", "/z/" };

            foreach (var sigo in sigos)
            {
                foreach (var path in paths)
                {
                    var key = path.Replace("/", "");
                    SigoAssert.Same(sigo.Get1(key), sigo.Get(path));
                }
            }
        }
Exemple #27
0
        public void Return_the_input_if_input_is_sigo()
        {
            var inputs = new object[] {
                Sigo.From("abc"),
                Sigo.Create(3),
                Sigo.Create(3).Set1("k", Sigo.From("v"))
            };

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

                SigoAssert.Same(o, sigo);
            }
        }
Exemple #28
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);
            }
        }
Exemple #29
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);
            }
        }
Exemple #30
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);
            }
        }