public void Changed() { AbstractSpreadsheet ss = new Spreadsheet(); Assert.IsFalse(ss.Changed); Set(ss, "C1", "17.5"); Assert.IsTrue(ss.Changed); }
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); }
private int wait_time = 0; // This is how many times second_process will run; #endregion Fields #region Constructors /// <summary> /// Creates a new spread sheet the user can interact with. /// </summary> public Form1() { InitializeComponent(); //sets the title of the spread sheet to 1 more than the one that opened it. this.Text = "DangerZone";//"Spreadsheet " + (SpreadsheetApplicationContext.getAppContext().get_form_count() + 1); my_spread_sheet = new Spreadsheet(IsValid, Normalize, "ps6"); //sets the initial user edit location to the contents box. contents_box.Select(); spreadsheetPanel1.SelectionChanged += update_display; spreadsheetPanel1.SetSelection(0, 0); unprocessed_commands = new Queue<string>(); old_contents = new Queue<string>(); changes_queue = new Queue<string>(); cells_to_recalulate = new HashSet<string>(); change_lock = new object();// This is the lock for when a current change is being done queue_lock = new object(); command_queue_lock = new object(); cell_name = string.Empty; spreadsheet_name = string.Empty; server_ready = true; waiting = false; undo_pending = false; send_ok = false; ignore_timer = false; ignore_timer1 = false; NewForm = null; OpenForm = null; }
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 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")); }
public void RunRandomizedTest(int seed, int size) { Spreadsheet s = new Spreadsheet(); Random rand = new Random(seed); for (int i = 0; i < 10000; i++) { try { switch (rand.Next(3)) { case 0: s.SetContentsOfCell(randomName(rand), "3.14"); break; case 1: s.SetContentsOfCell(randomName(rand), "hello"); break; case 2: s.SetContentsOfCell(randomName(rand), randomFormula(rand)); break; } } catch (CircularException) { } } ISet<string> set = new HashSet<string>(s.GetNamesOfAllNonemptyCells()); Assert.AreEqual(size, set.Count); }
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")); }
public void TestEmptyGetNamesOfCells() { Spreadsheet sheet = new Spreadsheet(); var nameEnum = sheet.GetNamesOfAllNonemptyCells().GetEnumerator(); nameEnum.MoveNext(); Assert.IsTrue(nameEnum.Current == null); }
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")); }
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); }
public void TestEmptyGetCellContents() { Spreadsheet sheet = new Spreadsheet(); object content = sheet.GetCellContents("A1"); Assert.IsTrue(content.Equals("")); }
/// <summary> /// Constructs a new Spreadsheet when you open a new spreadsheet from the server. /// </summary> /// <param name="filepath">Path to file</param> public Form1(string filepath, string user, int p, string pass) { InitializeComponent(); //ss = new Spreadsheet(filepath, isValidName, s => s.ToUpper(), "Spreadsheet"); ss = new Spreadsheet(isValidName, s => s.ToUpper(), filepath); fileList = new List<string>(); first = false; //Will this be bad?? scm = new SpreadsheetClientModel(); scm.Connect(user, p, pass); scm.SendMessage("CREATE" + "\\e" + filepath + "\n"); username = user; port = p; password = pass; version = 0; filename = filepath; this.Text = filename; spreadsheetPanel1.SetSelection(0, 0); selectedCell.Text = "A1"; selectedValue.Text = ""; editCell.Text = ""; scm.IncomingLineEvent += MessageReceived; UpdateCell(); //testing success //new OpenF(this, first); }
/// <summary> /// Constructor for Empty Spreadsheet Form /// </summary> public Form1() { InitializeComponent(); ss = new Spreadsheet(Validator, UppercaseString, version); updateTextBox(spreadsheetPanel1); }
public void TestCircularReference4() { AbstractSpreadsheet sheet = new Spreadsheet(); sheet.SetCellContents("A1", 2.0); sheet.SetCellContents("A1", new Formula("A1*B1*2/4")); Assert.Fail(); }
public void GetNamesOfAllNonemptyCellsTest3() { Spreadsheet test_spreadsheet = new Spreadsheet(); test_spreadsheet.SetCellContents("A1", "x+1"); Assert.AreEqual("A1", new List<string>(test_spreadsheet.GetNamesOfAllNonemptyCells())[0]); Assert.AreEqual(1, new List<string>(test_spreadsheet.GetNamesOfAllNonemptyCells()).Count); }
/// <summary> /// new constructor with spreasheet as parameter, and Spreadsheetmodel /// it will call the spreadsheet model constructor first /// </summary> /// <param name="ss"></param> public Form1(Spreadsheet ss, SpreadsheetModel ssm) : this() { this.ss = ss; this.spreadsheetmodel = ssm; BindingModelEvent(); }
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 NewTest11() { Spreadsheet s = new Spreadsheet(x => true, x => x, "\"default\""); s.SetContentsOfCell("a1", "Text"); s.Save("..\\..\\..\\Test.xml"); string sversion = s.GetSavedVersion("..\\..\\..\\Test.xml"); Assert.AreEqual("\"default\"", sversion); }
/// <summary> /// Creates a new empty spreadsheet /// </summary> public Form1() { InitializeComponent(); myModel = new SpreadsheetModel.SSModel(); myModel.CreateOK += ValidSS; myModel.CreateFail += InvalidSS; myModel.JoinOK += successJoin; myModel.JoinFail += failJoin; myModel.ChangeOk += successChange; myModel.ChangeWait += waitChange; myModel.ChangeFail += failChange; myModel.UndoOk += successUndo; myModel.UndoEnd += endUndo; myModel.UndoWait += waitUndo; myModel.UndoFail += failUndo; myModel.Update += update; myModel.SaveOk += successSave; myModel.SaveFail += failSave; myModel.Error += error; myModel.Test += tester; myModel.noConnection += connectError; myModel.invalidIP += badip; tabControl1.Appearance = TabAppearance.Buttons; tabControl1.SizeMode = TabSizeMode.Fixed; tabControl1.ItemSize = new System.Drawing.Size(0, 1); mySheet = new Spreadsheet(s => true/*Regex.IsMatch(s, "(^([a-z]|[A-Z])\\d+$)")*/, s => s.ToUpper(), "ps6"); numWindows++; int mycol; int myRow; int colLetter; string myVal; object content; //this.textBox1.Invoke(new Action(()=>textBox1.Clear())); textBox1.Clear(); //this.spreadsheetPanel1.Invoke(new Action(()=>spreadsheetPanel1.GetSelection(out mycol1, out myRow1))); spreadsheetPanel1.GetSelection(out mycol, out myRow); content = mySheet.GetCellContents(GetCellName(mycol, myRow)); if (content is Formula) { //this.textBox1.Invoke(new Action(()=>textBox1.Text = "=" + content.ToString())); textBox1.Text = "=" + content.ToString(); } else { //this.textBox1.Invoke(new Action(()=>textBox1.Text = content.ToString())); textBox1.Text = content.ToString(); } //this.spreadsheetPanel1.Invoke(new Action(()=>spreadsheetPanel1.GetValue(mycol1, myRow1, out myal1))); spreadsheetPanel1.GetValue(mycol, myRow, out myVal); colLetter = mycol + 65; //this.textBox2.Invoke(new Action(()=>textBox2.Text = ((char)colLetter).ToString() + (myRow1 + 1).ToString() + "= " + myval1)); textBox2.Text=((char)colLetter).ToString()+(myRow+1).ToString()+"= "+myVal; //this.Invoke(new Action(()=>this.Text = "Spreadsheet")); this.Text = "Spreadsheet"; }
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); }
public void GetNamesOfAllNonemptyCellsTest() { Spreadsheet s = new Spreadsheet(); s.SetContentsOfCell("a1", "20.0"); s.SetContentsOfCell("a2", "Hey there"); IEnumerable<string> names = s.GetNamesOfAllNonemptyCells(); Assert.AreEqual(true, names.Contains("a1")); Assert.AreEqual(true, names.Contains("a2")); }
public void ChangedTest() { 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(false, target.Changed); target.SetContentsOfCell("A1", "33"); Assert.AreEqual(true, target.Changed); }
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")); }
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")); }
/// <summary> /// Constructor for a Spreadsheet Form created from a file /// </summary> /// <param name="filename">The name of the file given</param> public Form1(string filename) { InitializeComponent(); ss = new Spreadsheet(filename, Validator, UppercaseString, version); updateTextBox(spreadsheetPanel1); //Make sure all the existing cells show up foreach (string name in ss.GetNamesOfAllNonemptyCells()) { updateCellValue(name); } }
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)); }
public void Changed() { // Make sure it starts false AbstractSpreadsheet s = new Spreadsheet(); Assert.IsFalse(s.Changed); // Modify a file, see if changed is true; Use SetContentsOfCell s.SetContentsOfCell("Z7", "1.5"); Assert.IsTrue(s.Changed); // Save a file after modifying, see if it switches back to false s.Save("changed_test.xml"); Assert.IsFalse(s.Changed); }
/// <summary> /// Creates a spreadsheetGUI with the content in sheet /// </summary> /// <param name="sheeet"></param> public SpreadsheetGUI(Spreadsheet sheet, string nameOfFile) { InitializeComponent(); // Create the spreadsheet model and the validator to check if the cell names are correct. spreadsheet = sheet; filename = nameOfFile; // registering a method so that it is notified when an event happens. spreadsheetPanel1.SelectionChanged += displaySelection; spreadsheetPanel1.SetSelection(2, 3); displaySelection(spreadsheetPanel1); // update display when loaded }
private Spreadsheet spreadsheet; // The spreadsheet model for the form. Each new form has its own spreadsheet. #endregion Fields #region Constructors /// <summary> /// Creates a new spreadsheetGUI and spreadsheet model /// </summary> public SpreadsheetGUI() { InitializeComponent(); // To convert the data from the server to regular data, we should just save it as xml then have // our spreadsheet open it for us. spreadsheet = new Spreadsheet(s => Regex.IsMatch(s, @"^[a-zA-Z]{1}[0-9]{1,2}$"), s => s.ToUpper(), "ps6"); // registering a method so that it is notified when an event happens. spreadsheetPanel1.SelectionChanged += displaySelection; spreadsheetPanel1.SetSelection(2, 3); //clientCommunication = new ClientSocketStuff("localhost", spreadsheet, Update, 1984); this.Shown += LoadStartupGUIConnection; }
//Have a string passed in that will be used to open a new form. /// <summary> /// Creates the Windows form. /// </summary> public MainGUI(String newSpreadsheet) { InitializeComponent(); spreadsheet = new Spreadsheet (s => Regex.IsMatch(s, @"^[a-zA-Z]{1}[0-9]{1,2}$"), s => s.ToUpper(), "ps6"); spreadsheetPanel1.SelectionChanged += LocationHandling; nameBox.Text = "A" + 1.ToString(); contentsBox.Focus(); contentsBox.Select(contentsBox.Text.Length, 0); this.Shown += LoadStartupGUIConnection; panelLock = new Object(); //location }
public Form1() { InitializeComponent(); //Register displaySelection as listener to selectionChanged spreadsheetPanel1.SelectionChanged += displaySelection; //Select cell A1 spreadsheetPanel1.SetSelection(0, 0); //Move cursor to ContentsField cellContentsField.Focus(); //create backing structure sheet = new SS.Spreadsheet(s => Regex.IsMatch(s, "^[A-Z]{1}[1-9]{1}[0-9]?$"), s => s.ToUpper(), "ps6"); //IsChanged is false initially isChanged = false; fileName = "Spreadsheet"; //Register Form1_Closing as listener to Exiting/Closing the sheet this.FormClosing += Form1_Closing; }
public void SaveTest8() { AbstractSpreadsheet ss = new Spreadsheet(); Set(ss, "A1", "hello"); Set(ss, "A2", "5.0"); Set(ss, "A3", "4.0"); Set(ss, "A4", "= A2 + A3"); ss.Save("save6.txt"); using (XmlReader reader = XmlReader.Create("save6.txt")) { int spreadsheetCount = 0; int cellCount = 0; bool A1 = false; bool A2 = false; bool A3 = false; bool A4 = false; string name = null; string contents = null; while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.Name) { case "spreadsheet": Assert.AreEqual("default", reader["version"]); spreadsheetCount++; break; case "cell": cellCount++; break; case "name": reader.Read(); name = reader.Value; break; case "contents": reader.Read(); contents = reader.Value; break; } } else { switch (reader.Name) { case "cell": if (name.Equals("A1")) { Assert.AreEqual("hello", contents); A1 = true; } else if (name.Equals("A2")) { Assert.AreEqual(5.0, Double.Parse(contents), 1e-9); A2 = true; } else if (name.Equals("A3")) { Assert.AreEqual(4.0, Double.Parse(contents), 1e-9); A3 = true; } else if (name.Equals("A4")) { contents = contents.Replace(" ", ""); Assert.AreEqual("=A2+A3", contents); A4 = true; } else { Assert.Fail(); } break; } } } Assert.AreEqual(1, spreadsheetCount); Assert.AreEqual(4, cellCount); Assert.IsTrue(A1); Assert.IsTrue(A2); Assert.IsTrue(A3); Assert.IsTrue(A4); } }
public void TestMethod10() { var spreadsheet = new SS.Spreadsheet(); spreadsheet.SetCellContents("A1", (string)null); }
public void EmptyArgument() { AbstractSpreadsheet ss = new Spreadsheet(); EmptyArgument(ss); }
public void Test18() { AbstractSpreadsheet s = new Spreadsheet(); Assert.IsFalse(s.GetNamesOfAllNonemptyCells().GetEnumerator().MoveNext()); }
public void Test3() { AbstractSpreadsheet s = new Spreadsheet(); Assert.AreEqual("", s.GetCellContents("A2")); }
public void Test2() { AbstractSpreadsheet s = new Spreadsheet(); s.GetCellContents("AA"); }
public void Test7() { AbstractSpreadsheet s = new Spreadsheet(); s.SetContentsOfCell("A8", (string)null); }
public void Test53() { TextReader dest = new StreamReader("../../Test52.xml"); AbstractSpreadsheet s = new Spreadsheet(dest); }
public void Test9() { AbstractSpreadsheet s = new Spreadsheet(); s.SetContentsOfCell("AZ", "hello"); }
public void Test8() { AbstractSpreadsheet s = new Spreadsheet(); s.SetContentsOfCell(null, "hello"); }
public void TestMethod14() { var spreadsheet = new SS.Spreadsheet(); spreadsheet.SetCellContents(null, 2.0); }
/// <summary> /// Gets the internal variable resolver for getting cells. /// Because the only thing we're allowed to make public is the /// already defined functions and the Constructor. So, we had /// to get tricky and make it a private Func so we can access it /// using the Private Object method. /// </summary> /// <param name="spreadsheet">The spreadsheet that we are getting the function from</param> /// <returns>The function that resolves variables</returns> private Func <string, double> _variableResolver(SS.Spreadsheet spreadsheet) { var privateObject = new PrivateObject(spreadsheet); return(privateObject.GetFieldOrProperty("_resolver") as Func <string, double>); }
public void TestMethod11() { var spreadsheet = new SS.Spreadsheet(); spreadsheet.SetCellContents("A1", (Formula)null); }
public void SaveTest2() { AbstractSpreadsheet ss = new Spreadsheet("q:\\missing\\save.txt", s => true, s => s, ""); }
public void OneFormula() { AbstractSpreadsheet ss = new Spreadsheet(); OneFormula(ss); }
public void SaveTest1() { AbstractSpreadsheet ss = new Spreadsheet(); ss.Save("q:\\missing\\save.txt"); }
public void Test1() { AbstractSpreadsheet s = new Spreadsheet(); s.GetCellContents(null); }
public void Formulas() { AbstractSpreadsheet ss = new Spreadsheet(); Formulas(ss); }
public void IsValidTest1() { AbstractSpreadsheet s = new Spreadsheet(); s.SetContentsOfCell("A1", "x"); }
public void NumberFormula2() { AbstractSpreadsheet ss = new Spreadsheet(); NumberFormula2(ss); }
public void Test5() { AbstractSpreadsheet s = new Spreadsheet(); s.SetContentsOfCell("A1A", "1.5"); }
public void ErrorArgument() { AbstractSpreadsheet ss = new Spreadsheet(); ErrorArgument(ss); }
/// <summary> /// Initialize the apreadsheet /// </summary> /// <param name="filePath"></param> public SpreadsheetForm(String filePath) : this() { thisSheet = new Spreadsheet(filePath, isValidDelegate, s => s.ToUpper(), "ps6"); }
public void StringArgument() { AbstractSpreadsheet ss = new Spreadsheet(); StringArgument(ss); }
public void MediumSheet() { AbstractSpreadsheet ss = new Spreadsheet(); MediumSheet(ss); }
public void DivisionByZero2() { AbstractSpreadsheet ss = new Spreadsheet(); DivisionByZero2(ss); }
public void OneNumber() { AbstractSpreadsheet ss = new Spreadsheet(); OneNumber(ss); }
public void TestMethod9() { var spreadsheet = new SS.Spreadsheet(); spreadsheet.SetCellContents("_+quack", 2.0); }
public void TestMethod1() { AbstractSpreadsheet s = new Spreadsheet(); s.SetContentsOfCell(null, "1.5"); }