Ejemplo n.º 1
0
        public void Test6()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents("Z7", 1.5);
            Assert.AreEqual(1.5, (double)s.GetCellContents("Z7"), 1e-9);
        }
Ejemplo n.º 2
0
        public void Test31()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents("A1", new Formula("B1+B2"));
            s.SetCellContents("B1", new Formula("C1-C2"));
            s.SetCellContents("B2", new Formula("C3*C4"));
            s.SetCellContents("C1", new Formula("D1*D2"));
            s.SetCellContents("C2", new Formula("D3*D4"));
            s.SetCellContents("C3", new Formula("D5*D6"));
            s.SetCellContents("C4", new Formula("D7*D8"));
            s.SetCellContents("D1", new Formula("E1"));
            s.SetCellContents("D2", new Formula("E1"));
            s.SetCellContents("D3", new Formula("E1"));
            s.SetCellContents("D4", new Formula("E1"));
            s.SetCellContents("D5", new Formula("E1"));
            s.SetCellContents("D6", new Formula("E1"));
            s.SetCellContents("D7", new Formula("E1"));
            s.SetCellContents("D8", new Formula("E1"));
            ISet <String> cells = s.SetCellContents("E1", 0);

            AssertSetEqualsIgnoreCase(new HashSet <string>()
            {
                "A1", "B1", "B2", "C1", "C2", "C3", "C4", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "E1"
            }, cells);
        }
Ejemplo n.º 3
0
        public void Test22()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents("B1", new Formula("3.5"));
            AssertSetEqualsIgnoreCase(s.GetNamesOfAllNonemptyCells(), new string[] { "B1" });
        }
Ejemplo n.º 4
0
        public void Test14()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents("A1", new Formula("A2"));
            s.SetCellContents("A2", new Formula("A1"));
        }
Ejemplo n.º 5
0
        public void Test18()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents("B1", "");
            Assert.IsFalse(s.GetNamesOfAllNonemptyCells().GetEnumerator().MoveNext());
        }
Ejemplo n.º 6
0
        public void RunRandomizedTest(int seed, int size)
        {
            TestableSpreadsheet s = new TestableSpreadsheet();
            Random rand           = new Random(seed);

            for (int i = 0; i < 10000; i++)
            {
                try
                {
                    switch (rand.Next(3))
                    {
                    case 0:
                        s.SetCellContents(randomName(rand), 3.14);
                        break;

                    case 1:
                        s.SetCellContents(randomName(rand), "hello");
                        break;

                    case 2:
                        s.SetCellContents(randomName(rand), randomFormula(rand));
                        break;
                    }
                }
                catch (CircularException)
                {
                }
            }
            ISet <string> set = new HashSet <string>(s.GetNamesOfAllNonemptyCells());

            Assert.AreEqual(size, set.Count);
        }
Ejemplo n.º 7
0
        public void Test10()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents("Z7", "hello");
            Assert.AreEqual("hello", s.GetCellContents("Z7"));
        }
Ejemplo n.º 8
0
        public void Test29()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents("A1", new Formula("A2+A3"));
            s.SetCellContents("A1", "Hello");
            Assert.AreEqual("Hello", (string)s.GetCellContents("A1"));
        }
Ejemplo n.º 9
0
        public void Test26()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents("A1", 17.2);
            s.SetCellContents("B1", "hello");
            AssertSetEqualsIgnoreCase(s.SetCellContents("C1", new Formula("5")), new string[] { "C1" });
        }
Ejemplo n.º 10
0
        public void Test30()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents("A1", "Hello");
            s.SetCellContents("A1", new Formula("23"));
            Assert.AreEqual(23, ((Formula)s.GetCellContents("A1")).Evaluate(x => 0));
        }
Ejemplo n.º 11
0
        public void Test28()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents("A1", new Formula("A2+A3"));
            s.SetCellContents("A1", 2.5);
            Assert.AreEqual(2.5, (double)s.GetCellContents("A1"), 1e-9);
        }
Ejemplo n.º 12
0
        public void Test15()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents("A1", new Formula("A2+A3"));
            s.SetCellContents("A3", new Formula("A4+A5"));
            s.SetCellContents("A5", new Formula("A6+A7"));
            s.SetCellContents("A7", new Formula("A1+A1"));
        }
Ejemplo n.º 13
0
        public void Test13()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents("Z7", new Formula("3"));
            Formula f = (Formula)s.GetCellContents("Z7");

            Assert.AreEqual(3, f.Evaluate(x => 0), 1e-6);
        }
Ejemplo n.º 14
0
        public void Test35()
        {
            TestableSpreadsheet s     = new TestableSpreadsheet();
            ISet <String>       cells = new HashSet <string>();

            for (int i = 1; i < 200; i++)
            {
                cells.Add("A" + i);
                AssertSetEqualsIgnoreCase(cells, s.SetCellContents("A" + i, new Formula("A" + (i + 1))));
            }
        }
Ejemplo n.º 15
0
        public void Test27()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents("A1", new Formula("A2+A3"));
            s.SetCellContents("A2", 6);
            s.SetCellContents("A3", new Formula("A2+A4"));
            s.SetCellContents("A4", new Formula("A2+A5"));
            HashSet <string> result = new HashSet <string>(s.SetCellContents("A5", 82.5));

            AssertSetEqualsIgnoreCase(result, new string[] { "A5", "A4", "A3", "A1" });
        }
Ejemplo n.º 16
0
        public void Test39()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            for (int i = 1; i < 200; i++)
            {
                s.SetCellContents("A" + i, new Formula("A" + (i + 1)));
            }
            try
            {
                s.SetCellContents("A150", new Formula("A50"));
                Assert.Fail();
            }
            catch (CircularException)
            {
            }
        }
Ejemplo n.º 17
0
        public void Test16()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            try
            {
                s.SetCellContents("A1", new Formula("A2+A3"));
                s.SetCellContents("A2", 15);
                s.SetCellContents("A3", 30);
                s.SetCellContents("A2", new Formula("A3*A1"));
            }
            catch (CircularException e)
            {
                Assert.AreEqual(15, (double)s.GetCellContents("A2"), 1e-9);
                throw e;
            }
        }
Ejemplo n.º 18
0
        public void Test43()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            for (int i = 0; i < 500; i++)
            {
                s.SetCellContents("A1" + i, new Formula("A1" + (i + 1)));
            }

            ISet <string> sss = s.SetCellContents("A1499", 25.0);

            Assert.AreEqual(500, sss.Count);
            for (int i = 0; i < 500; i++)
            {
                Assert.IsTrue(sss.Contains("A1" + i) || sss.Contains("a1" + i));
            }

            sss = s.SetCellContents("A1249", 25.0);
            Assert.AreEqual(250, sss.Count);
            for (int i = 0; i < 250; i++)
            {
                Assert.IsTrue(sss.Contains("A1" + i) || sss.Contains("a1" + i));
            }
        }
Ejemplo n.º 19
0
        public void Test5()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents("A1A", 1.5);
        }
Ejemplo n.º 20
0
        public void Test4()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents(null, 1.5);
        }
Ejemplo n.º 21
0
        public void Test11()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents(null, new Formula("2"));
        }
Ejemplo n.º 22
0
        public void Test9()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents("AZ", "hello");
        }
Ejemplo n.º 23
0
        public void Test7()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents("A8", (string)null);
        }
Ejemplo n.º 24
0
        public void Test8()
        {
            TestableSpreadsheet s = new TestableSpreadsheet();

            s.SetCellContents(null, "hello");
        }