private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (path != null) { CsTimerData.WriteCsTimerData(path, collectedData); } }
private void enterTimeBox_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (enterTimeBox.Text == "") { } else if (enterTimeBox.Text == "next") { scrambleLabel.Text = Alg.FromRandomMoves(random.Next(15, 25), random).ToString(); enterTimeBox.Text = ""; } else if (enterTimeBox.Text.All(char.IsDigit)) { collectedData.Add(new CsTimerData() { Number = collectedData.Count + 1, Date = DateTime.Now, Scramble = scrambleLabel.Text, Milliseconds = int.Parse(enterTimeBox.Text) }); scrambleLabel.Text = Alg.FromRandomMoves(random.Next(15, 25), random).ToString(); enterTimeBox.Text = ""; } else if (File.Exists(enterTimeBox.Text)) { if (path != null) { CsTimerData.WriteCsTimerData(path, collectedData); } path = enterTimeBox.Text; collectedData.Clear(); CsTimerData.ReadCsTimerData(path, it => collectedData.Add(it)); enterTimeBox.Text = ""; scrambleLabel.Text = Alg.FromRandomMoves(random.Next(15, 25), random).ToString(); } else { enterTimeBox.Text = "Invalid: " + enterTimeBox.Text; } } }
public void ReadWriteTest() { var collection = new List <CsTimerData>(); string testCasePath = "../../../csTimerDataTestCase.csv"; string resultPath = "../../../csTimerDataTestResult.csv"; CsTimerData.ReadCsTimerData(testCasePath, data => collection.Add(data)); CsTimerData.WriteCsTimerData(resultPath, collection); using StreamReader testCaseReader = new StreamReader(new FileStream(testCasePath, FileMode.Open)), resultReader = new StreamReader(new FileStream(resultPath, FileMode.Open)); string expectedLine, actualLine; int line = 0; while ((expectedLine = testCaseReader.ReadLine()) != null && (actualLine = resultReader.ReadLine()) != null) { Assert.AreEqual(expectedLine, actualLine, "problem on line number " + line++ + " (0-indexed)"); } }