Example #1
0
        public void TestMethod3()
        {
            var spreadsheet = new SS.Spreadsheet();

            spreadsheet.SetCellContents("A1", 1);
            spreadsheet.SetCellContents("A2", 2);
            spreadsheet.SetCellContents("A3", new Formula("A1 + A2"));
            spreadsheet.SetCellContents("B1", 3);
            spreadsheet.SetCellContents("B2", 4);
            spreadsheet.SetCellContents("B3", new Formula("B1 + B2"));
            spreadsheet.SetCellContents("C3", new Formula("A3 + B3"));
            spreadsheet.SetCellContents("D3", new Formula("C3 / 2"));

            var resolve = _variableResolver(spreadsheet);

            var a3 = spreadsheet.GetCellContents("A3") as Formula;
            var b3 = spreadsheet.GetCellContents("B3") as Formula;
            var c3 = spreadsheet.GetCellContents("C3") as Formula;
            var d3 = spreadsheet.GetCellContents("D3") as Formula;

            Assert.IsNotNull(a3);
            Assert.IsNotNull(b3);
            Assert.IsNotNull(c3);
            Assert.IsNotNull(d3);

            Assert.AreEqual(3d, a3.Evaluate(resolve));
            Assert.AreEqual(7d, b3.Evaluate(resolve));
            Assert.AreEqual(10d, c3.Evaluate(resolve));
            Assert.AreEqual(5d, d3.Evaluate(resolve));
        }
Example #2
0
        public void TestMethod4()
        {
            var spreadsheet = new SS.Spreadsheet();

            spreadsheet.SetCellContents("A1", "Title");
            spreadsheet.SetCellContents("A2", "Tesla #1");
            spreadsheet.SetCellContents("A3", "Tesla #2");
            spreadsheet.SetCellContents("A4", "Tesla #3");
            spreadsheet.SetCellContents("A5", "Total:");

            spreadsheet.SetCellContents("B1", "Sales");
            spreadsheet.SetCellContents("B2", 75000);
            spreadsheet.SetCellContents("B3", 85000);
            spreadsheet.SetCellContents("B4", 90000);
            spreadsheet.SetCellContents("B5", new Formula("B2+B3+B4"));

            var resolve = _variableResolver(spreadsheet);

            var a1 = spreadsheet.GetCellContents("A1") as string;
            var b2 = spreadsheet.GetCellContents("B2") as double?;
            var b5 = spreadsheet.GetCellContents("B5") as Formula;

            Assert.IsNotNull(a1);
            Assert.IsNotNull(b2);
            Assert.IsNotNull(b5);

            Assert.AreEqual("Title", a1);
            Assert.AreEqual(75000, b2);
            Assert.AreEqual(75000 + 85000 + 90000d, b5.Evaluate(resolve));
        }
Example #3
0
 public void SetStringContentTwice()
 {
     Spreadsheet sheet = new Spreadsheet();
     sheet.SetCellContents("A1", "blue");
     sheet.SetCellContents("A1", "green");
     Assert.AreEqual(sheet.GetCellContents("A1"), "green");
     Assert.AreNotEqual(sheet.GetCellContents("A1"), "blue");
 }
 public void GetCellContentsStringTest()
 {
     //Gets the contents of a string-type cell
     Spreadsheet s = new Spreadsheet();
     s.SetContentsOfCell("a1", "Hey there");
     Assert.AreEqual("Hey there", s.GetCellContents("a1"));
 }
 public void GetCellContentsStringCellExistsTest()
 {
     Spreadsheet s = new Spreadsheet();
     Assert.AreEqual(true, s.SetContentsOfCell("a1", "Hey there").Contains("a1"));
     Assert.AreEqual(true, s.SetContentsOfCell("a1", "What's up?").Contains("a1"));
     Assert.AreEqual("What's up?", s.GetCellContents("a1"));
 }
Example #6
0
        public void TestEmptyGetCellContents()
        {
            Spreadsheet sheet = new Spreadsheet();
            object content = sheet.GetCellContents("A1");

            Assert.IsTrue(content.Equals(""));
        }
Example #7
0
 public void GetValueDoubleEmptyConstructor()
 {
     Spreadsheet sheet = new Spreadsheet();
     sheet.SetContentsOfCell("D1", "5");
     Assert.AreEqual(sheet.GetCellContents("D1"), (double)5);
     Assert.AreEqual(sheet.GetCellValue("D1"), (double)5);
 }
Example #8
0
 public void GetValueFormula01()
 {
     Spreadsheet sheet = new Spreadsheet(s => true, s => s, "default");
     sheet.SetContentsOfCell("D1", "=5");
     Assert.AreEqual(sheet.GetCellContents("D1"), new Formula("5"));
     Assert.AreEqual(sheet.GetCellValue("D1"), (double)5);
 }
Example #9
0
        public void TestMethod13()
        {
            var spreadsheet = new SS.Spreadsheet();
            var resolve     = _variableResolver(spreadsheet);
            var random      = new Random();

            for (var x = 'A'; x <= 'Z'; x++)
            {
                double sum        = 0;
                var    expression = "";

                const int count = 30;
                for (var y = 1; y < count; y++)
                {
                    var cell      = x.ToString() + y;
                    var randomNum = random.Next(1, 200);

                    spreadsheet.SetCellContents(cell, randomNum);
                    sum += randomNum;

                    // Adds the cell with a + //
                    expression += (y == count - 1) ? cell : cell + "+";
                }

                var cellName = x + count.ToString();

                spreadsheet.SetCellContents(cellName, new Formula(expression));

                var formula = spreadsheet.GetCellContents(cellName) as Formula;

                Assert.IsNotNull(formula);

                Assert.AreEqual(sum, formula.Evaluate(resolve));
            }
        }
Example #10
0
        /// <summary>
        /// Gets the contents of a given cell from the model and places it in the current cell contents box
        /// for updating
        /// </summary>
        private void SetCellContentsBox()
        {
            SpreadsheetPanel panel = window.GetSpreadsheetPanel();
            // set the location of this textbox
            int x, y, width, height;

            panel.GetSelectionLocation(out x, out y, out width, out height);

            window.UpdateEditBoxLocation(x, y, width, height);

            // locate the current cell in the grid and convert to a variable
            panel.GetSelection(out int col, out int row);
            string cellName = ConvertRowColToCellName(row, col);

            // set the contents text to the current contents of the cell
            object contents = sheet.GetCellContents(cellName);

            if (contents is string || contents is double)
            {
                window.ContentsBoxText = contents.ToString();
            }
            else
            {
                window.ContentsBoxText = "=" + contents.ToString();
            }
        }
 public void GetCellContentsDoubleCellExistsTest()
 {
     Spreadsheet s = new Spreadsheet();
     Assert.AreEqual(true, s.SetContentsOfCell("a1", "2.0").Contains("a1"));
     Assert.AreEqual(true, s.SetContentsOfCell("a1", "5.3").Contains("a1"));
     Assert.AreEqual(5.3, s.GetCellContents("a1"));
 }
Example #12
0
        public void TestConstructor()
        {
            //just some stuff with filewriting
            Assert.IsTrue(sheet1.IsValid("any old string"));
            Assert.IsTrue(sheet1.Normalize("dead") == "dead");
            Assert.IsTrue(sheet1.Version == "default");

            //test 3 arg constructor
            sheet1 = new Spreadsheet(s => (s.Length >= 2) ? true : false,
                s => s.Replace(" ", ""),
                "version1");
            Assert.IsTrue(sheet1.IsValid("A1"));
            Assert.IsFalse(sheet1.IsValid("A"));
            Assert.IsTrue(sheet1.Normalize("d e a d") == "dead");
            Assert.IsTrue(sheet1.Version == "version1");
            sheet1.SetContentsOfCell("A     1","loaded!");

            string savePath = "save 1.xml";
            sheet1.Save(savePath);
            sheet1 = new Spreadsheet(
                savePath,
                s => (s.Length >= 2) ? true : false,
                s => s.Replace(" ", ""),
                "version1");
            Assert.AreEqual("loaded!",(string)sheet1.GetCellContents("A1"));
        }
Example #13
0
        public void GetCellContentsFormula()
        {
            Spreadsheet sheet = new Spreadsheet();
            sheet.SetCellContents("A1", "blue");
            sheet.SetCellContents("A1", "green");
            sheet.SetCellContents("B1", "purple");
            sheet.SetCellContents("C1", "red");
            sheet.SetCellContents("D1", new Formula("C1 + 2 + X1"));

            Assert.AreEqual(sheet.GetCellContents("D1"), new Formula("C1+2+X1"));
        }
Example #14
0
 public void TestConstructor1()
 {
     AbstractSpreadsheet sheet = new Spreadsheet();
     Assert.AreEqual("", sheet.GetCellContents("A1"));
     Assert.AreEqual("", sheet.GetCellContents("B1"));
     Assert.AreEqual("", sheet.GetCellContents("D1"));
     Assert.AreEqual("", sheet.GetCellContents("AA1"));
     Assert.AreEqual("", sheet.GetCellContents("Jim"));
     Assert.AreEqual("", sheet.GetCellContents("ab1"));
 }
Example #15
0
        public void TestMethod15()
        {
            var spreadsheet = new SS.Spreadsheet();

            spreadsheet.SetCellContents("A1", 2.0);
            spreadsheet.SetCellContents("C1", new Formula("A1"));

            var resolve = _variableResolver(spreadsheet);

            var formula = spreadsheet.GetCellContents("C1") as Formula;

            Assert.IsNotNull(formula);
            Assert.AreEqual(formula, new Formula("A1"));

            Assert.AreEqual(2d, formula.Evaluate(resolve));
        }
Example #16
0
        public void TestMethod7()
        {
            var spreadsheet = new SS.Spreadsheet();

            spreadsheet.SetCellContents("_kanye_west", 2.0);
            spreadsheet.SetCellContents("_kanye_north", 45.0);
            spreadsheet.SetCellContents("C1", new Formula("_kanye_west + _kanye_north"));

            var resolve = _variableResolver(spreadsheet);

            var formula = spreadsheet.GetCellContents("C1") as Formula;

            Assert.IsNotNull(formula);
            Assert.AreEqual(formula, new Formula("_kanye_west + _kanye_north"));

            Assert.AreEqual(47.0d, formula.Evaluate(resolve));
        }
Example #17
0
        /// <summary>
        /// Gets the contents of a given cell from the model and places it in the current cell contents box
        /// for updating
        /// </summary>
        private void SetCellContentsBox(SpreadsheetPanel panel)
        {
            // locate the current cell in the grid and convert to a variable
            panel.GetSelection(out int col, out int row);
            string cellName = ConvertRowColToCellName(row, col);

            // set the contents text to the current contents of the cell
            object contents = sheet.GetCellContents(cellName);

            if (contents is string || contents is double)
            {
                window.ContentsBoxText = contents.ToString();
            }
            else
            {
                window.ContentsBoxText = "=" + contents.ToString();
            }
        }
Example #18
0
        public void TestMethod2()
        {
            var spreadsheet = new SS.Spreadsheet();

            spreadsheet.SetCellContents("A1", 2.0);
            spreadsheet.SetCellContents("B1", 45.0);
            spreadsheet.SetCellContents("C1", new Formula("A1 + B1"));
            spreadsheet.SetCellContents("D1", new Formula("C1 + A1"));

            var resolve = _variableResolver(spreadsheet);

            var d1 = spreadsheet.GetCellContents("D1") as Formula;

            Assert.IsNotNull(d1);
            Assert.AreEqual(d1, new Formula("C1 + A1"));

            Assert.AreEqual(49.0d, d1.Evaluate(resolve));
        }
 private void changed_size(object sender, EventArgs e)
 {
     sss.SetSelection(0, 0);
     cellTextBox.Location = new System.Drawing.Point(42, 79);
     cellboxY             = 0;
     cellboxX             = 0;
     if (sheet.GetCellContents("A1") == null)
     {
         cellTextBox.Text       = "";
         cellContentsField.Text = "";
         cellValueField.Text    = "";
     }
     else
     {
         cellContentsField.Text = sheet.GetCellContents("A1").ToString();
         cellValueField.Text    = sheet.GetCellValue("A1").ToString();
         cellTextBox.Text       = sheet.GetCellValue("A1").ToString();
     }
     cellNameField.Text = "A1";
 }
        /// <summary>
        /// set the name and the contents of the cell
        /// </summary>
        private void SetCellNameAndContents()
        {
            spreadsheetPanel.GetSelection(out int col, out int row);
            // get and then set the cell name
            selectedCellNameTextBox.Text = "" + (char)(col + 65) + (row + 1);
            object currCellContents = thisSheet.GetCellContents(selectedCellNameTextBox.Text);
            string stringContents;

            if (currCellContents is Formula)
            {
                stringContents = "=" + currCellContents.ToString();
            }
            else
            {
                stringContents = currCellContents.ToString();
            }
            selectedCellContentsTextBox.Text = stringContents;
            spreadsheetPanel.SetValue(col, row, thisSheet.GetCellValue(selectedCellNameTextBox.Text).ToString());
            // get and then set the cell value
            selectedCellValueTextBox.Text = thisSheet.GetCellValue(selectedCellNameTextBox.Text).ToString();

            string cellName     = selectedCellNameTextBox.Text;
            string cellContents = selectedCellContentsTextBox.Text;
        }
Example #21
0
 public void CreateSaveLoadSpreadsheet()
 {
     Spreadsheet sheet = new Spreadsheet();
     sheet.SetContentsOfCell("D1", "=5");
     sheet.SetContentsOfCell("C1", "=4.5");
     sheet.SetContentsOfCell("E1", "apples");
     sheet.SetContentsOfCell("G1", "-2");
     sheet.SetContentsOfCell("H1", "-4");
     sheet.SetContentsOfCell("F1", "= G1 + H1");
     sheet.Save(@"MyXml2.xml");
     Spreadsheet sheet2 = new Spreadsheet(@"MyXml2.xml", s => true, s => s, "default");
     Assert.AreEqual(sheet2.GetCellContents("D1"), new Formula("5"));
     Assert.AreEqual(sheet2.GetCellContents("C1"), new Formula("4.5"));
     Assert.AreEqual(sheet2.GetCellContents("E1"), "apples");
     Assert.AreEqual(sheet2.GetCellContents("G1"), (double)-2);
     Assert.AreEqual(sheet2.GetCellContents("H1"), (double)-4);
     Assert.AreEqual(sheet2.GetCellContents("F1"), new Formula("G1 + H1"));
     Assert.AreEqual(sheet2.GetCellValue("F1"), (double)-6);
 }
Example #22
0
        /// <summary>
        /// Given cell name, moves cursor to contents field,
        /// and updates name, contents, and value fields
        /// with values corresponding to cell
        /// </summary>
        /// <param name="name"></param>
        private void UpdateGUIFields(string name)
        {
            //move cursor to contents field
            cellContentsField.Focus();

            cellNameField.Text = name;

            //set CellContentsField from spreadsheet
            if (sheet.GetCellContents(name) is Formula)
            {
                cellContentsField.Text = "=" + sheet.GetCellContents(name).ToString();
            }
            else
            {
                cellContentsField.Text = sheet.GetCellContents(name).ToString();
            }

            //set CellValueField from spreadsheet
            cellValueField.Text = sheet.GetCellValue(name).ToString();

            //highlight current contents
            cellContentsField.SelectionStart  = 0;
            cellContentsField.SelectionLength = cellContentsField.Text.Length;
        }
Example #23
0
 public void Test300()
 {
     Spreadsheet s = new Spreadsheet();
     Assert.AreEqual("", s.GetCellContents("A2"));
 }
Example #24
0
 public void Test2800()
 {
     Spreadsheet s = new Spreadsheet();
     s.SetContentsOfCell("A1", "=A2+A3");
     s.SetContentsOfCell("A1", "2.5");
     Assert.AreEqual(2.5, (double)s.GetCellContents("A1"), 1e-9);
 }
Example #25
0
 public void Test1700()
 {
     Spreadsheet s = new Spreadsheet();
     try {
         s.SetContentsOfCell("A1", "=A2+A3");
         s.SetContentsOfCell("A2", "15");
         s.SetContentsOfCell("A3", "30");
         s.SetContentsOfCell("A2", "=A3*A1");
     }
     catch (CircularException e) {
         Assert.AreEqual(15, (double)s.GetCellContents("A2"), 1e-9);
         throw e;
     }
 }
Example #26
0
 public void NormalizeTest2()
 {
     AbstractSpreadsheet ss = new Spreadsheet(s => true, s => s.ToUpper(), "");
     ss.SetContentsOfCell("B1", "hello");
     Assert.AreEqual("hello", ss.GetCellContents("b1"));
 }
Example #27
0
 public void Test1400()
 {
     Spreadsheet s = new Spreadsheet();
     s.SetContentsOfCell("Z7", "=3");
     Formula f = (Formula)s.GetCellContents("Z7");
     Assert.AreEqual(new Formula("3"), f);
     Assert.AreNotEqual(new Formula("2"), f);
 }
Example #28
0
 public void TestRead3()
 {
     string path = "read3.xml";
     Spreadsheet sheet = new Spreadsheet();
     sheet.SetContentsOfCell("a1", "=1.5+4");
     sheet.SetContentsOfCell("b2", "=a2-2.6");
     sheet.SetContentsOfCell("c3", "=3.7*e5");
     sheet.SetContentsOfCell("d4", "hil");
     sheet.SetContentsOfCell("e5", "5.9");
     sheet.Save(path);
     HashSet<string> original = (HashSet<string>)sheet.GetNamesOfAllNonemptyCells();
     Spreadsheet sheet2 = new Spreadsheet(path, x => true, s => s, "default");
     foreach (string s in original) {
         Assert.IsTrue(sheet.GetCellContents(s).Equals(sheet2.GetCellContents(s)));
         Assert.IsTrue(sheet.GetCellValue(s).Equals(sheet2.GetCellValue(s)));
     }
 }
Example #29
0
 public void TestGetCellContents6()
 {
     Spreadsheet sheet = new Spreadsheet();
     sheet.SetContentsOfCell("a1", "5.27");
     sheet.SetContentsOfCell("b2", "6.000");
     sheet.SetContentsOfCell("c3", "hello");
     sheet.SetContentsOfCell("d4", "=5 - 4 + x2");
     sheet.SetContentsOfCell("e5", "=a1 - b2");
     Assert.AreEqual(5.27, sheet.GetCellContents("a1"));
     Assert.AreEqual(6.0, sheet.GetCellContents("b2"));
     Assert.AreEqual("hello", sheet.GetCellContents("c3"));
     Assert.AreEqual(new Formula("5 - 4 + x2"), sheet.GetCellContents("d4"));
     Assert.AreEqual(new Formula("a1 - b2"), sheet.GetCellContents("e5"));
 }
Example #30
0
        public void Test2()
        {
            AbstractSpreadsheet s = new Spreadsheet();

            s.GetCellContents("AA");
        }
        public void GetCellContents6()
        {
            AbstractSpreadsheet sheet = new Spreadsheet();

            Assert.AreEqual("", sheet.GetCellContents("a1"));
        }
Example #32
0
        public void Test1()
        {
            Spreadsheet s = new Spreadsheet();

            s.GetCellContents(null);
        }
Example #33
0
        public void Test2()
        {
            Spreadsheet s = new Spreadsheet();

            s.GetCellContents("1AA");
        }
Example #34
0
        public void Test3()
        {
            Spreadsheet s = new Spreadsheet();

            Assert.AreEqual("", s.GetCellContents("A2"));
        }
Example #35
0
 public void TestGetCellContents5()
 {
     Spreadsheet sheet = new Spreadsheet();
     sheet.SetContentsOfCell("a57", "hello");
     Assert.AreEqual("hello", sheet.GetCellContents("a57"));
 }
Example #36
0
        public void TestException6()
        {
            Spreadsheet ss = new Spreadsheet();

            ss.GetCellContents("AXYAHNKD23490&8558");
        }
Example #37
0
 public void Test100()
 {
     Spreadsheet s = new Spreadsheet();
     s.GetCellContents(null);
 }
Example #38
0
        public void TestException4()
        {
            Spreadsheet ss = new Spreadsheet();

            ss.GetCellContents("X1X");
        }
Example #39
0
 public void Test1000()
 {
     Spreadsheet s = new Spreadsheet();
     s.SetContentsOfCell("Z7", "hello");
     Assert.AreEqual("hello", s.GetCellContents("Z7"));
 }
Example #40
0
        public void TestGetCellContents()
        {
            AbstractSpreadsheet ss = new Spreadsheet();

            Assert.AreEqual("", ss.GetCellContents("z1"));
        }
Example #41
0
 public void NormalizeTest1()
 {
     AbstractSpreadsheet s = new Spreadsheet();
     s.SetContentsOfCell("B1", "hello");
     Assert.AreEqual("", s.GetCellContents("b1"));
 }
Example #42
0
        public void StressTest1()
        {
            Spreadsheet sheet = new Spreadsheet();

            int SIZE = 1000;
            // Add a ton of items
            for (int i = 0; i < SIZE; i++)
                sheet.SetContentsOfCell("a" + i, 1.0 + i + "");

            for (int i = 0; i < SIZE; i++)
                sheet.SetContentsOfCell("b" + i, "hi" + i);

            for (int i = 0; i < SIZE; i++)
                sheet.SetContentsOfCell("c" + i, "=5+" + i);

            // Make correct HashSet
            HashSet<string> correct = new HashSet<string>();
            for (int i = 0; i < SIZE; i++)
                correct.Add("a" + i);
            for (int i = 0; i < SIZE; i++)
                correct.Add("b" + i);
            for (int i = 0; i < SIZE; i++)
                correct.Add("c" + i);

            // Get all of the names of the cells
            HashSet<string> output = (HashSet<string>)sheet.GetNamesOfAllNonemptyCells();

            // Confirm that the names in the spreadsheet are correct
            Assert.IsTrue(correct.SetEquals(output));

            // Check the cell contents of all the cells
            for (int i = 0; i < SIZE; i++)
                Assert.AreEqual(1.0 + i, sheet.GetCellContents("a" + i));
            for (int i = 0; i < SIZE; i++)
                Assert.AreEqual("hi" + i, sheet.GetCellContents("b" + i));
            for (int i = 0; i < SIZE; i++)
                Assert.AreEqual(new Formula("5+" + i), sheet.GetCellContents("c" + i));

            // You did it!
            Assert.IsTrue(true);
        }
Example #43
0
 public void SaveTest3()
 {
     AbstractSpreadsheet s1 = new Spreadsheet();
     Set(s1, "A1", "hello");
     s1.Save("save1.txt");
     s1 = new Spreadsheet("save1.txt", s => true, s => s, "default");
     Assert.AreEqual("hello", s1.GetCellContents("A1"));
 }
Example #44
0
        public void TestException1()
        {
            Spreadsheet ss = new Spreadsheet();

            ss.GetCellContents(null);
        }
Example #45
0
 public void Test200()
 {
     Spreadsheet s = new Spreadsheet();
     s.GetCellContents("1AA");
 }
Example #46
0
 public void TestGetCellContents3()
 {
     Spreadsheet sheet = new Spreadsheet();
     Assert.AreEqual("", sheet.GetCellContents("a1"));
 }
Example #47
0
 public void Test2900()
 {
     Spreadsheet s = new Spreadsheet();
     s.SetContentsOfCell("A1", "=A2+A3");
     s.SetContentsOfCell("A1", "Hello");
     Assert.AreEqual("Hello", (string)s.GetCellContents("A1"));
 }
Example #48
0
 public void TestGetCellContents4()
 {
     Spreadsheet sheet = new Spreadsheet();
     sheet.SetContentsOfCell("a1", "0.0");
     Assert.AreEqual(0.0, sheet.GetCellContents("a1"));
 }
Example #49
0
 public void Test3000()
 {
     Spreadsheet s = new Spreadsheet();
     s.SetContentsOfCell("A1", "Hello");
     s.SetContentsOfCell("A1", "=23");
     Assert.AreEqual(new Formula("23"), (Formula)s.GetCellContents("A1"));
     Assert.AreNotEqual(new Formula("24"), (Formula)s.GetCellContents("A1"));
 }
        public void TestGetCellContents1()
        {
            AbstractSpreadsheet sheet = new Spreadsheet();

            sheet.GetCellContents(null);
        }
Example #51
0
 public void Test600()
 {
     Spreadsheet s = new Spreadsheet();
     s.SetContentsOfCell("Z7", "1.5");
     Assert.AreEqual(1.5, (double)s.GetCellContents("Z7"), 1e-9);
 }
        public void TestGetCellContents2()
        {
            AbstractSpreadsheet sheet = new Spreadsheet();

            sheet.GetCellContents("hello");
        }