예제 #1
0
 public void NewTest1()
 {
     Spreadsheet sheet = new Spreadsheet();
     sheet.SetContentsOfCell("A1", "3");
     sheet.SetContentsOfCell("B1", "=A1");
     Assert.AreEqual(sheet.GetCellValue("B1"), 3.0);
     sheet.SetContentsOfCell("A1", "");
     Assert.IsTrue(sheet.GetCellValue("B1") is FormulaError);
 }
예제 #2
0
        public void GetCellValueTest()
        {
            AbstractSpreadsheet s = new Spreadsheet();
            string name;
            string content;
            // Try a value of a string from string
            name = "A1";
            content = "Hello";
            s.SetContentsOfCell(name, content);
            string expected1 = content;
            string actual1 = (string)s.GetCellValue(name);
            Assert.AreEqual(expected1, actual1);

            // Try a value of a double from a double
            name = "B1";
            content = "3";
            s.SetContentsOfCell(name, content);
            double expected2 = 3;
            double actual2 = (double)s.GetCellValue(name);
            Assert.AreEqual(expected2, actual2);

            // Try a value of a double from a Formula
            name = "C1";
            content = "=3+1";
            s.SetContentsOfCell(name, content);
            double expected3 = 4;
            double actual3 = (double)s.GetCellValue(name);
            Assert.AreEqual(expected3, actual3);

            // Try all possible FormulaError
            name = "D1";
            content = "=1/0";
            s.SetContentsOfCell(name, content);
            object actual4 = s.GetCellValue(name);
            Assert.IsInstanceOfType(actual4, typeof(FormulaError));

            // Try chaining several formulas together then changing the value of cell. Test before and after.
            s.SetContentsOfCell("E1", "=F1 + 1");
            s.SetContentsOfCell("F1", "=G1 + 1");
            s.SetContentsOfCell("G1", "1");
            Assert.AreEqual(3, (double)s.GetCellValue("E1"));
            Assert.AreEqual(2, (double)s.GetCellValue("F1"));

            s.SetContentsOfCell("G1", "2");
            Assert.AreEqual(4, (double)s.GetCellValue("E1"));
            Assert.AreEqual(3, (double)s.GetCellValue("F1"));

            // Try switching a cell that has a formula depending on it to string.
            s.SetContentsOfCell("J1", "This is a string");
            s.SetContentsOfCell("K1", "=J1");
            Assert.IsInstanceOfType(s.GetCellValue("K1"), typeof(FormulaError));
        }
예제 #3
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);
 }
예제 #4
0
        public void Test54()
        {
            TextReader          dest = new StreamReader("../../Test52.xml");
            AbstractSpreadsheet s    = new Spreadsheet(dest);

            Assert.AreEqual(23.0, s.GetCellValue("A1"));
        }
예제 #5
0
        /// <summary>
        /// Opens an existing Spreadsheet from a file.
        /// The constuctor will update the GUI on what needs to be displayed.
        /// </summary>
        /// <param name="filePath">Path and name of file</param>
        public SSForm(string filePath)
        {
            this.fileName = filePath;
            InitializeComponent();

            personalSpreadsheet = new Spreadsheet(filePath, validAddress, s => s.ToUpper(), "PS6");

            int    col, row;
            object cellVal;

            foreach (string cellName in personalSpreadsheet.GetNamesOfAllNonemptyCells()) //Assigns the string rep for each cell that is not empty in spreadsheet.
            {
                addressToGrid(cellName, out col, out row);                                // Get the current address based on cell name.
                cellVal = personalSpreadsheet.GetCellValue(cellName);
                spreadsheetPanel1.SetValue(col, row, cellVal.ToString());                 // Set the value of cell using grid address.
            }
            string focusCellValue;

            spreadsheetPanel1.GetValue(0, 0, out focusCellValue); //Gets the starting positions value.
            valueBox.Text   = focusCellValue;                     // Displays the default's value.
            addressBox.Text = "A1";
            contentBox.Text = personalSpreadsheet.GetCellContents(gridToAddress(0, 0)).ToString();
            fileName        = filePath;
            this.Text       = fileName;
        }
예제 #6
0
        /// <summary>
        /// Helper method that given an enumerable collection of cell names to update will update the corresponding values on a spreadsheet panel
        /// </summary>
        /// <param name="cellsToUpdate">enumerable collection of cells by name to update</param>
        private void UpdateSpreadsheetPanelValues(IEnumerable <string> cellsToUpdate)
        {
            // Update dependent cells value to display
            foreach (string cellNameToUpdate in cellsToUpdate)
            {
                object           cellValueToUpdate = spreadsheet.GetCellValue(cellNameToUpdate);
                Tuple <int, int> colRowToUpdate    = CellNameToColRow(cellNameToUpdate); // Convert the given cell name to a column and row location
                string           strCellValueToUpdate;
                if (cellValueToUpdate is FormulaError)                                   // With a FormulaError we will get the Reason and that will be the cell value
                {
                    strCellValueToUpdate = ((FormulaError)cellValueToUpdate).Reason;
                }
                else if (cellValueToUpdate is double) // With a double we convert to a string
                {
                    strCellValueToUpdate = cellValueToUpdate.ToString();
                }
                else // Otherwise we have a string so we cast to a string
                {
                    strCellValueToUpdate = (string)cellValueToUpdate;
                }


                FormSpreadsheetPanel.SetValue(colRowToUpdate.Item1, colRowToUpdate.Item2, strCellValueToUpdate); // Update displayed value
            }
        }
예제 #7
0
        public void SetContentsOfCell5()
        {
            AbstractSpreadsheet sheet = new Spreadsheet();

            sheet.SetContentsOfCell("B1", "asdf");
            Assert.AreEqual("asdf", sheet.GetCellValue("B1"));
        }
예제 #8
0
        public void SetContentsOfCell4()
        {
            AbstractSpreadsheet sheet = new Spreadsheet();

            sheet.SetContentsOfCell("B1", "=2+3");
            Assert.AreEqual(5.0, sheet.GetCellValue("B1"));
        }
예제 #9
0
 public void GetValueDouble()
 {
     Spreadsheet sheet = new Spreadsheet(s => true, s => s, "default");
     sheet.SetContentsOfCell("D1", "5");
     Assert.AreEqual(sheet.GetCellContents("D1"), (double)5);
     Assert.AreEqual(sheet.GetCellValue("D1"), (double)5);
 }
예제 #10
0
        public void ConstructorTest1()
        {
            Regex r = new Regex("");
            AbstractSpreadsheet sheet = new Spreadsheet(r);

            sheet.SetContentsOfCell("A1", "5");
            Assert.AreEqual(5.0, sheet.GetCellValue("A1"));
        }
예제 #11
0
        public void NormalizeTest3()
        {
            AbstractSpreadsheet ss = new Spreadsheet();

            ss.SetContentsOfCell("a1", "5");
            ss.SetContentsOfCell("A1", "6");
            ss.SetContentsOfCell("B1", "= a1");
            Assert.AreEqual(6.0, (double)ss.GetCellValue("B1"), 1e-9);
        }
예제 #12
0
        public void TestSetContentsNewValueBadFormula()
        {
            Spreadsheet ss = new Spreadsheet();

            ss.SetContentsOfCell("A1", "3.0");
            ss.SetContentsOfCell("B1", "2.0");
            ss.SetContentsOfCell("C1", "0");

            Assert.AreEqual(3.0, ss.GetCellValue("A1"));
            Assert.AreEqual(2.0, ss.GetCellValue("B1"));
            Assert.AreEqual(0.0, ss.GetCellValue("C1"));

            ss.SetContentsOfCell("D1", "=A1*2.0");
            Assert.AreEqual(6.0, ss.GetCellValue("D1"));

            ss.SetContentsOfCell("F1", "=B1/C1");
            Assert.AreEqual(new FormulaError(), ss.GetCellValue("F1"));
        }
예제 #13
0
        public void Test51()
        {
            AbstractSpreadsheet s = new Spreadsheet();

            s.SetContentsOfCell("A1", "=" + new Formula("A2+A3").ToString());
            s.SetContentsOfCell("A2", "6");
            s.SetContentsOfCell("A3", "=" + new Formula("A2+A4").ToString());
            s.SetContentsOfCell("A4", "=" + new Formula("A2+A5").ToString());
            s.SetContentsOfCell("A5", "5");
            Assert.AreEqual(23.0, s.GetCellValue("A1"));
        }
예제 #14
0
        /// <summary>
        /// Replaces the current value text box to the looked-up value of the cell
        /// </summary>
        private void SetCellValueBox(SpreadsheetPanel panel)
        {
            // locates the current cell in the grid and converts it to a variable
            panel.GetSelection(out int col, out int row);
            string cellName = ConvertRowColToCellName(row, col);

            // set the "value" object to the value of the variable
            object value = sheet.GetCellValue(cellName);

            // if value is a string or double then convert the object to a string
            if (value is string || value is double)
            {
                window.ValueBoxText = value.ToString();
            }
            // else text box value will be set to FormulaError
            else
            {
                window.ValueBoxText = "FormulaError";
            }
        }
예제 #15
0
        public void LongTest()
        {
            AbstractSpreadsheet s = new Spreadsheet();

            s.SetContentsOfCell("sum1", "= a1 + a2");
            int i;
            int depth = 100;

            for (i = 1; i <= depth * 2; i += 2)
            {
                s.SetContentsOfCell("a" + i, "= a" + (i + 2) + " + a" + (i + 3));
                s.SetContentsOfCell("a" + (i + 1), "= a" + (i + 2) + "+ a" + (i + 3));
            }
            s.SetContentsOfCell("a" + i, "1");
            s.SetContentsOfCell("a" + (i + 1), "1");
            Assert.AreEqual(Math.Pow(2, depth + 1), (double)s.GetCellValue("sum1"), 1e20);
            s.SetContentsOfCell("a" + i, "0");
            Assert.AreEqual(Math.Pow(2, depth), (double)s.GetCellValue("sum1"), 1e20);
            s.SetContentsOfCell("a" + (i + 1), "0");
            Assert.AreEqual(0.0, (double)s.GetCellValue("sum1"), 0.1);
        }
예제 #16
0
        /// <summary>
        /// event that deels with selecting a cell, if cell already has contents it populates the approperiate labels with content information
        /// </summary>
        /// <param name="sender">spreadsheetPanel</param>
        private void SpreadsheetPanel1_Selection(SpreadsheetPanel sender)
        {
            //clears previous content
            ContentsBox.Clear();
            ValueBox.Clear();
            int row;
            int col;

            //used to get letter portion of cell name.
            char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
            spreadsheetPanel1.GetSelection(out col, out row);
            //adds 1 to row to set name in spreadsheet cell to match panel labels.
            row += 1;
            AddressLabel.Text = "" + alpha[col] + row + ":";
            //sets name for cell using row and col integers
            string name = "" + alpha[col] + row;

            string contents = sheet.GetCellContents(name).ToString();
            string value    = sheet.GetCellValue(name).ToString();

            //checks if formula is an error if so sets cell contents to error message and error label.

            if (value == "SpreadsheetUtilities.FormulaError")
            {
                spreadsheetPanel1.SetValue(col, row - 1, "Formula Error");
                ValueBox.Text = "Formula Error";
            }
            //otherwise sets the value and proper content to appropreiate labels and cell.
            else
            {
                ValueBox.Text = value;
                spreadsheetPanel1.SetValue(col, row - 1, value);
            }
            //sets the contents of input box to what is in the current cell.
            ContentsBox.Focus();
            ContentsBox.Text = contents;
        }
예제 #17
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;
        }
        /// <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;
        }
예제 #19
0
        /// <summary>
        /// Recieves a Change from the server and applys it to the spreadsheet
        /// </summary>
        private void Recieve_Change(object sender, EventArgs e)
        {
            int col, row;

            spreadsheetPanel1.GetSelection(out col, out row);
            string           address       = gridToAddress(col, row);
            string           content       = contentBox.Text;
            HashSet <string> cellsToUpdate = null;

            try {
                // set the contents and determine cells to recalculate
                cellsToUpdate = (HashSet <string>)personalSpreadsheet.SetContentsOfCell(address, content);
                foreach (string cell in cellsToUpdate)
                {
                    //get col, row
                    addressToGrid(cell, out col, out row);

                    object value = personalSpreadsheet.GetCellValue(cell);
                    if (value is FormulaError)
                    {
                        value = ((FormulaError)value).Reason; // display the reason for error
                    }
                    //set value to display at cell
                    spreadsheetPanel1.SetValue(col, row, value.ToString());
                }
                addressBox.Text = address;
                string cellVal;
                addressToGrid(address, out col, out row);
                spreadsheetPanel1.GetValue(col, row, out cellVal);
                valueBox.Text = cellVal;

                if (personalSpreadsheet.Changed && (!Regex.IsMatch(this.Text, @"(\(unsaved\))$")))
                {
                    this.Text = this.Text + " (unsaved)";
                }
            }
            catch (Exception err) //something went wrong while setting the contents
            {
                MessageBox.Show(err.Message, "Error Detected!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                contentBox.SelectAll();
                contentBox.Focus();
            }
        }
예제 #20
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);
 }
예제 #21
0
        public void TestSave()
        {
            Spreadsheet ss = new Spreadsheet();

            ss.SetContentsOfCell("A1", "3.0");
            ss.SetContentsOfCell("B1", "2.0");
            ss.SetContentsOfCell("C1", "4.0");

            Assert.AreEqual(3.0, ss.GetCellValue("A1"));
            Assert.AreEqual(2.0, ss.GetCellValue("B1"));
            Assert.AreEqual(4.0, ss.GetCellValue("C1"));

            ss.SetContentsOfCell("D1", "=A1*2.0");
            Assert.AreEqual(6.0, ss.GetCellValue("D1"));

            ss.SetContentsOfCell("F1", "=B1*C1");
            Assert.AreEqual(8.0, ss.GetCellValue("F1"));

            ss.SetContentsOfCell("E1", "=D1*C1");
            Assert.AreEqual(24.0, ss.GetCellValue("E1"));

            ss.SetContentsOfCell("G1", "=D1*E1");
            ss.SetContentsOfCell("F1", "hello");
            Assert.AreEqual(144.0, ss.GetCellValue("G1"));

            TextWriter tw = new StreamWriter("../../XMLFile1 - Copy.xml");

            ss.Save(tw);

            StreamReader sr = new StreamReader("../../XMLFile1 - Copy.xml");
            Spreadsheet  s2 = new Spreadsheet(sr);

            Assert.AreEqual(3.0, s2.GetCellValue("A1"));
            Assert.AreEqual(2.0, s2.GetCellValue("B1"));
            Assert.AreEqual(4.0, s2.GetCellValue("C1"));
            Assert.AreEqual(24.0, s2.GetCellValue("E1"));
            Assert.AreEqual(144.0, s2.GetCellValue("G1"));
            Assert.AreEqual("hello", s2.GetCellValue("F1"));
        }
예제 #22
0
        public void TestSetContentsNewValue()
        {
            Spreadsheet ss = new Spreadsheet();

            ss.SetContentsOfCell("A1", "3.0");
            ss.SetContentsOfCell("B1", "2.0");
            ss.SetContentsOfCell("C1", "4.0");

            Assert.AreEqual(3.0, ss.GetCellValue("A1"));
            Assert.AreEqual(2.0, ss.GetCellValue("B1"));
            Assert.AreEqual(4.0, ss.GetCellValue("C1"));

            ss.SetContentsOfCell("D1", "=A1*2.0");
            Assert.AreEqual(6.0, ss.GetCellValue("D1"));

            ss.SetContentsOfCell("F1", "=B1*C1");
            Assert.AreEqual(8.0, ss.GetCellValue("F1"));

            ss.SetContentsOfCell("E1", "=D1*C1");
            Assert.AreEqual(24.0, ss.GetCellValue("E1"));

            ss.SetContentsOfCell("G1", "=D1*E1");
            Assert.AreEqual(144.0, ss.GetCellValue("G1"));
        }
예제 #23
0
        public void SpreadsheetConstructorTest1()
        {
            string existing_path = @"..\..\..\SpreadSheetTests\validspreadsheet.xml"; // the .. means up a directory

            Spreadsheet target = new Spreadsheet(existing_path, s => true, s => s.ToUpper(), "dan1");
            Assert.AreEqual(2.0, (double)target.GetCellValue("a2"));
        }
예제 #24
0
        public void GetValueFormula04()
        {
            Spreadsheet sheet = new Spreadsheet(s => true, s => s, "default");
            sheet.SetContentsOfCell("D1", "=5");
            sheet.SetContentsOfCell("C1", "=4.5");
            sheet.SetContentsOfCell("E1", "0.5");
            sheet.SetContentsOfCell("F1", "13");
            Assert.AreEqual(sheet.GetCellValue("D1"), (double)5);
            Assert.AreEqual(sheet.GetCellValue("C1"), (double)4.5);
            Assert.AreEqual(sheet.GetCellValue("E1"), (double)0.5);
            Assert.AreEqual(sheet.GetCellValue("F1"), (double)13);

            sheet.SetContentsOfCell("B1", "=(C1 + D1)/E1 + F1");
            Assert.AreEqual(sheet.GetCellContents("B1"), new Formula("(C1 + D1)/E1 + F1"));
            Assert.AreEqual(sheet.GetCellValue("B1"), (double)32);
        }
예제 #25
0
 public void TestGetCellValue2()
 {
     Spreadsheet sheet = new Spreadsheet();
     sheet.GetCellValue("84");
 }
예제 #26
0
 public void NewTest15()
 {
     Spreadsheet s = new Spreadsheet(x => true, x => x.Replace('a', '1'), "default");
     s.SetContentsOfCell("a1", "Text");
     s.GetCellValue("a1");
 }
예제 #27
0
 public void NewTest19()
 {
     Spreadsheet s = new Spreadsheet(x => true, x => x.Replace('a', '1'), "default");
     s.GetCellValue("a1");
 }
예제 #28
0
 /// <summary>
 /// Handles a request to change the selected cell.
 /// The view should handle highliting the new cell, itself.
 /// </summary>
 private void HandleSelectedCellChanged(string name)
 {
     selectedCell = name;
     window.DisplayContents(spreadsheet.GetCellContents(name).ToString());
     window.DisplayValue(spreadsheet.GetCellValue(name));
 }
예제 #29
0
        public void GetValueFormula02()
        {
            Spreadsheet sheet = new Spreadsheet(s => true, s => s, "default");
            sheet.SetContentsOfCell("D1", "=5");
            sheet.SetContentsOfCell("C1", "=4.5");
            Assert.AreEqual(sheet.GetCellValue("D1"), (double)5);
            Assert.AreEqual(sheet.GetCellValue("C1"), (double)4.5);

            sheet.SetContentsOfCell("B1", "=C1+D1");
            Assert.AreEqual(sheet.GetCellContents("B1"), new Formula("C1 + D1"));
            Assert.AreEqual(sheet.GetCellValue("B1"), (double)9.5);
        }
예제 #30
0
 public void GetCellValueTest()
 {
     Spreadsheet target = new Spreadsheet();
     target.SetContentsOfCell("a1", "2");
     double mydouble = 2;
     string name = "a1";
     object expected = mydouble;
     object actual;
     actual = target.GetCellValue(name);
     Assert.AreEqual(expected, actual);
     //Assert.Inconclusive("Verify the correctness of this test method.");
 }
 public void GetCellValueFromStringTest()
 {
     Spreadsheet s = new Spreadsheet();
     s.SetContentsOfCell("a1", "Hello");
     Assert.AreEqual("Hello", s.GetCellValue("a1"));
 }
 public void GetCellValueFromDoubleTest()
 {
     Spreadsheet s = new Spreadsheet();
     s.SetContentsOfCell("a1", "2.0");
     Assert.AreEqual(2.0, s.GetCellValue("a1"));
 }
예제 #33
0
        public void GetValueFormulaMultipleCellLayers02()
        {
            Spreadsheet sheet = new Spreadsheet();
            Assert.IsTrue(!sheet.Changed);
            sheet.SetContentsOfCell("D1", "=5");
            Assert.IsTrue(sheet.Changed);
            sheet.SetContentsOfCell("C1", "=4.5");
            sheet.SetContentsOfCell("E1", "0.5");
            sheet.SetContentsOfCell("G1", "-2");
            sheet.SetContentsOfCell("H1", "-4");
            sheet.SetContentsOfCell("F1", "= G1 + H1");
            Assert.AreEqual(sheet.GetCellValue("D1"), (double)5);
            Assert.AreEqual(sheet.GetCellValue("C1"), (double)4.5);
            Assert.AreEqual(sheet.GetCellValue("E1"), (double)0.5);
            Assert.AreEqual(sheet.GetCellValue("F1"), (double)-6);
            Assert.AreEqual(sheet.GetCellValue("G1"), (double)-2);

            sheet.SetContentsOfCell("B1", "=(C1 + D1)/E1 + F1");
            Assert.AreEqual(sheet.GetCellContents("B1"), new Formula("(C1 + D1)/E1 + F1"));
            Assert.AreEqual(sheet.GetCellValue("B1"), (double)13);
        }
예제 #34
0
        public void GetValueFormula04EmptyConstructor()
        {
            Spreadsheet sheet = new Spreadsheet();
            Assert.IsTrue(!sheet.Changed);
            sheet.SetContentsOfCell("D1", "=5");
            Assert.IsTrue(sheet.Changed );
            sheet.SetContentsOfCell("C1", "=4.5");
            sheet.SetContentsOfCell("E1", "0.5");
            sheet.SetContentsOfCell("F1", "13");
            Assert.AreEqual(sheet.GetCellValue("D1"), (double)5);
            Assert.AreEqual(sheet.GetCellValue("C1"), (double)4.5);
            Assert.AreEqual(sheet.GetCellValue("E1"), (double)0.5);
            Assert.AreEqual(sheet.GetCellValue("F1"), (double)13);

            sheet.SetContentsOfCell("B1", "=(C1 + D1)/E1 + F1");
            Assert.AreEqual(sheet.GetCellContents("B1"), new Formula("(C1 + D1)/E1 + F1"));
            Assert.AreEqual(sheet.GetCellValue("B1"), (double)32);
        }
예제 #35
0
 public void LongTest()
 {
     AbstractSpreadsheet s = new Spreadsheet();
     s.SetContentsOfCell("sum1", "= a1 + a2");
     int i;
     int depth = 100;
     for (i = 1; i <= depth * 2; i += 2)
     {
         s.SetContentsOfCell("a" + i, "= a" + (i + 2) + " + a" + (i + 3));
         s.SetContentsOfCell("a" + (i + 1), "= a" + (i + 2) + "+ a" + (i + 3));
     }
     s.SetContentsOfCell("a" + i, "1");
     s.SetContentsOfCell("a" + (i + 1), "1");
     Assert.AreEqual(Math.Pow(2, depth + 1), (double)s.GetCellValue("sum1"), 1e20);
     s.SetContentsOfCell("a" + i, "0");
     Assert.AreEqual(Math.Pow(2, depth), (double)s.GetCellValue("sum1"), 1e20);
     s.SetContentsOfCell("a" + (i + 1), "0");
     Assert.AreEqual(0.0, (double)s.GetCellValue("sum1"), 0.1);
 }
예제 #36
0
        public void TestException19()
        {
            Spreadsheet ss = new Spreadsheet();

            ss.GetCellValue("fniu4h&*Y*(&*(&U*UH#u904u");
        }
예제 #37
0
 /// <summary>
 /// Gets cell value from Spreadsheet cell.
 /// </summary>
 /// <param name="name">Cell Name</param>
 /// <returns></returns>
 public object GetCellValue(string name)
 {
     return(s.GetCellValue(name));
 }
예제 #38
0
        public void GetCellValueTest1()
        {
            Spreadsheet target = new Spreadsheet();
            target = new Spreadsheet();

            target.SetContentsOfCell("A1", "10.0");

            target.SetContentsOfCell("A3", "=A1 + A4");
            target.SetContentsOfCell("A4", "5");
            target.SetContentsOfCell("A2", "=A1 + A3");
            Assert.AreEqual(15.0, (double)target.GetCellValue("A3"), 1e-9);

            Assert.AreEqual(25.0, (double)target.GetCellValue("A2"), 1e-9);
        }
예제 #39
0
 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";
 }
예제 #40
0
        public void SaveTest()
        {
            string existing_path = @"..\..\..\SpreadSheetTests\validspreadsheet.xml"; // the .. means up a directory

            Spreadsheet target = new Spreadsheet(existing_path, s => true, s => s.ToUpper(), "dan1");
            Assert.AreEqual(2.0, (double)target.GetCellValue("a2"));
            target.Save(@"output22.xml");
            var output = File.ReadAllText("output22.xml");
            Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-8\"?><spreadsheet version=\"dan1\"><cell><name>A1</name><contents>2</contents></cell><cell><name>A2</name><contents>=A1</contents></cell></spreadsheet>", output);
        }
예제 #41
0
 public void NewTest16()
 {
     Spreadsheet s = new Spreadsheet(x => true, x => x, "default");
     s.GetCellValue("1a");
 }
예제 #42
0
        public void GetValueFormula02EmptyConstructor()
        {
            Spreadsheet sheet = new Spreadsheet();
            sheet.SetContentsOfCell("D1", "=5");
            sheet.SetContentsOfCell("C1", "=4.5");
            Assert.AreEqual(sheet.GetCellValue("D1"), (double)5);
            Assert.AreEqual(sheet.GetCellValue("C1"), (double)4.5);

            sheet.SetContentsOfCell("B1", "=C1+D1");
            Assert.AreEqual(sheet.GetCellContents("B1"), new Formula("C1 + D1"));
            Assert.AreEqual(sheet.GetCellValue("B1"), (double)9.5);
        }
예제 #43
0
 public void NewTest14()
 {
     Spreadsheet s = new Spreadsheet(x => true, x => x, "default");
     s.SetContentsOfCell("1a", "Text");
     s.GetCellValue("1a");
 }
예제 #44
0
 public void LongFormulaHelper(out object result)
 {
     try {
         AbstractSpreadsheet s = new Spreadsheet();
         s.SetContentsOfCell("sum1", "= a1 + a2");
         int i;
         int depth = 100;
         for (i = 1; i <= depth * 2; i += 2) {
             s.SetContentsOfCell("a" + i, "= a" + (i + 2) + " + a" + (i + 3));
             s.SetContentsOfCell("a" + (i + 1), "= a" + (i + 2) + "+ a" + (i + 3));
         }
         s.SetContentsOfCell("a" + i, "1");
         s.SetContentsOfCell("a" + (i + 1), "1");
         Assert.AreEqual(Math.Pow(2, depth + 1), (double)s.GetCellValue("sum1"), 1.0);
         s.SetContentsOfCell("a" + i, "0");
         Assert.AreEqual(Math.Pow(2, depth), (double)s.GetCellValue("sum1"), 1.0);
         s.SetContentsOfCell("a" + (i + 1), "0");
         Assert.AreEqual(0.0, (double)s.GetCellValue("sum1"), 0.1);
         result = "ok";
     }
     catch (Exception e) {
         result = e;
     }
 }
예제 #45
0
 public void TestGetCellValue1()
 {
     Spreadsheet sheet = new Spreadsheet();
     string s = null;
     sheet.GetCellValue(s);
 }
예제 #46
0
 public void NormalizeTest4()
 {
     AbstractSpreadsheet ss = new Spreadsheet(s => true, s => s.ToUpper(), "");
     ss.SetContentsOfCell("a1", "5");
     ss.SetContentsOfCell("A1", "6");
     ss.SetContentsOfCell("B1", "= a1");
     Assert.AreEqual(6.0, (double)ss.GetCellValue("B1"), 1e-9);
 }
예제 #47
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)));
     }
 }
예제 #48
0
        public void GetValueFormula03EmptyConstructor()
        {
            Spreadsheet sheet = new Spreadsheet();
            sheet.SetContentsOfCell("D1", "=5");
            sheet.SetContentsOfCell("C1", "=4.5");
            Assert.AreEqual(sheet.GetCellValue("D1"), (double)5);
            Assert.AreEqual(sheet.GetCellValue("C1"), (double)4.5);
            Assert.AreEqual(sheet.GetCellValue("E1"), "");
            Assert.AreEqual(sheet.GetCellValue("F1"), "");

            sheet.SetContentsOfCell("B1", "=(C1 + D1)/E1 + F1");
            Assert.AreEqual(sheet.GetCellContents("B1"), new Formula("(C1 + D1)/E1 + F1"));
            Assert.IsTrue(sheet.GetCellValue("B1") is FormulaError);
        }
예제 #49
0
 public void NormalizeTest3()
 {
     AbstractSpreadsheet s = new Spreadsheet();
     s.SetContentsOfCell("a1", "5");
     s.SetContentsOfCell("A1", "6");
     s.SetContentsOfCell("B1", "= a1");
     Assert.AreEqual(5.0, (double)s.GetCellValue("B1"), 1e-9);
 }
예제 #50
0
        public void TestException18()
        {
            Spreadsheet ss = new Spreadsheet();

            ss.GetCellValue(null);
        }
예제 #51
0
        public void GetCellValueTest()
        {
            Spreadsheet target = new Spreadsheet();
            string name = "A1";
            target.SetContentsOfCell(name, "88.0");

            Assert.AreEqual(88.0, (double)target.GetCellValue(name), 1e-9);

            target = new Spreadsheet();
            name = "A1";
            target.SetContentsOfCell(name, "88.0");

            Assert.AreEqual(88.0, (double)target.GetCellValue(name), 1e-9);

            target = new Spreadsheet();
            name = "A1";
            target.SetContentsOfCell(name, "10.0");
            target.SetContentsOfCell("A2", "=A1 + A1");
            Assert.AreEqual(20.0, (double)target.GetCellValue("A2"), 1e-9);

            target = new Spreadsheet();
            name = "A1";
            target.SetContentsOfCell(name, "10.0");
            target.SetContentsOfCell("A4", "5");
            target.SetContentsOfCell("A3", "=A1 + A4");
            target.SetContentsOfCell("A2", "=A1 + A3");

            Assert.AreEqual(25.0, (double)target.GetCellValue("A2"), 1e-9);

            target = new Spreadsheet();
            name = "A1";
            target.SetContentsOfCell(name, "10.0");
            target.SetContentsOfCell("A4", "5");
            target.SetContentsOfCell("A3", "=A1 + A4");
            target.SetContentsOfCell("A2", "=A1 + A3");
            target.SetContentsOfCell("A3", "5");
            Assert.AreEqual(15.0, (double)target.GetCellValue("A2"), 1e-9);
        }
 public void SpreadsheetFourArgumentConstructorTest()
 {
     if (!File.Exists("fourarg.xml"))
     {
         Spreadsheet old = new Spreadsheet(TestValidToTrue, TestNormalizeToUpperCase, "2.2");
         old.SetContentsOfCell("A1", "asdf");
         old.SetContentsOfCell("B2", "23");
         old.Save("fourarg.xml");
     }
     Spreadsheet s = new Spreadsheet("fourarg.xml", TestValidToTrue, TestNormalizeToUpperCase, "2.2");
     Assert.AreEqual(true, s.IsValid("a"));
     Assert.AreEqual("A", s.Normalize("a"));
     Assert.AreEqual("asdf", s.GetCellContents("A1"));
     Assert.AreEqual(23.0, s.GetCellContents("B2"));
     Assert.AreEqual(23.0, s.GetCellValue("B2"));
     Assert.AreEqual("2.2", s.Version);
 }