Пример #1
0
        public void Checkoutにより中身が切り替わること()
        {
            var set = new HappySet <TestClass>(10)
            {
                new TestClass("a")
            };

            var aid = set.Commit("a");

            set.Add(new TestClass("b"));
            var bid = set.Commit("b");

            Assert.AreEqual(2, set.Count);
            Assert.AreEqual(2, set.CommitCount);
            Assert.AreEqual(2, set.Logs().Count);

            set.Checkout(aid);

            Assert.AreEqual(1, set.Count);
            Assert.AreEqual(2, set.CommitCount);
            Assert.AreEqual(2, set.Logs().Count);

            set.Checkout(bid);

            Assert.AreEqual(2, set.Count);
            Assert.AreEqual(2, set.CommitCount);
            Assert.AreEqual(2, set.Logs().Count);

            set.Add(new TestClass("c"));
            set.Commit("c");

            set.Add(new TestClass("d"));
            var did = set.Commit("d");

            Assert.AreEqual(4, set.Count);
            Assert.AreEqual(4, set.CommitCount);
            Assert.AreEqual(4, set.Logs().Count);

            set.Checkout(bid);

            Assert.AreEqual(2, set.Count);
            Assert.AreEqual(4, set.CommitCount);
            Assert.AreEqual(4, set.Logs().Count);

            set.Checkout(did);

            Assert.AreEqual(4, set.Count);
            Assert.AreEqual(4, set.CommitCount);
            Assert.AreEqual(4, set.Logs().Count);

            set.Checkout(did);

            Assert.AreEqual(4, set.Count);
            Assert.AreEqual(4, set.CommitCount);
            Assert.AreEqual(4, set.Logs().Count);

            set.Checkout(aid);

            set.Add(new TestClass("e"));
            var eid = set.Commit("e");

            Assert.AreEqual(2, set.Count);
            Assert.AreEqual(5, set.CommitCount);
            Assert.AreEqual(5, set.Logs().Count);

            var a = set.ElementAt(0);

            set.Remove(a);
            set.Commit("f");

            Assert.AreEqual(1, set.Count);
            Assert.AreEqual(6, set.CommitCount);
            Assert.AreEqual(6, set.Logs().Count);

            set.Checkout(eid);

            Assert.AreEqual(2, set.Count);
            Assert.AreEqual(6, set.CommitCount);
            Assert.AreEqual(6, set.Logs().Count);
        }
Пример #2
0
        public void HappySetの中身が正しいこと()
        {
            var set = new HappySet <TestClass>
            {
                new TestClass("1"),
                new TestClass("2")
            };

            Assert.AreEqual("1", set.ElementAt(0).Hoge);
            Assert.AreEqual("2", set.ElementAt(1).Hoge);

            set.Commit("a");
            set.Add(new TestClass("3"));
            set.Commit("b");

            Assert.AreEqual("1", set.ElementAt(0).Hoge);
            Assert.AreEqual("2", set.ElementAt(1).Hoge);
            Assert.AreEqual("3", set.ElementAt(2).Hoge);

            Assert.AreEqual("a", set.Logs()[0].Message);

            var id = set.Logs()[0].Id;

            set.Checkout(id);
            Assert.AreEqual(2, set.CommitCount);

            Assert.AreEqual("1", set.ElementAt(0).Hoge);
            Assert.AreEqual("2", set.ElementAt(1).Hoge);

            var set2 = set.CherryPick(id);

            Assert.AreEqual("1", set2.ElementAt(0).Hoge);
            Assert.AreEqual("2", set2.ElementAt(1).Hoge);

            set2.Add(new TestClass("3"));

            Assert.AreEqual("1", set2.ElementAt(0).Hoge);
            Assert.AreEqual("2", set2.ElementAt(1).Hoge);
            Assert.AreEqual("3", set2.ElementAt(2).Hoge);

            Assert.AreEqual("1", set.ElementAt(0).Hoge);
            Assert.AreEqual("2", set.ElementAt(1).Hoge);

            id = set.Logs()[1].Id;

            set.Checkout(id);
            Assert.AreEqual(2, set.CommitCount);

            Assert.AreEqual("1", set.ElementAt(0).Hoge);
            Assert.AreEqual("2", set.ElementAt(1).Hoge);
            Assert.AreEqual("3", set.ElementAt(2).Hoge);

            set = new HappySet <TestClass>
            {
                new TestClass("a"),
                new TestClass("b")
            };

            Assert.AreEqual("a", set.ElementAt(0).Hoge);
            Assert.AreEqual("b", set.ElementAt(1).Hoge);
        }