public void TryParseSuccess(SuccessCase <int> data) { var pos = data.Start; Assert.AreEqual(true, IntReader.TryReadInt32(data.Text, ref pos, out var actual)); Assert.AreEqual(data.Expected, actual); Assert.AreEqual(data.ExpectedEnd, pos); }
public void TryParseError(ErrorCase <int> @case) { var pos = @case.Start; Assert.AreEqual(false, IntReader.TryReadInt32(@case.Text, ref pos, out var actual)); Assert.AreEqual(@case.Expected, actual); Assert.AreEqual(@case.ExpectedEnd, pos); }
public void TryParseError(ErrorCase <int> @case) { int pos = @case.Start; int actual; var success = IntReader.TryReadInt32(@case.Text, ref pos, out actual); Assert.AreEqual(false, success); Assert.AreEqual(@case.Expected, actual); Assert.AreEqual(@case.ExpectedEnd, pos); }
public void TryParseError(ErrorData <int> data) { int pos = data.Start; int actual; var success = IntReader.TryReadInt32(data.Text, ref pos, out actual); Assert.AreEqual(false, success); Assert.AreEqual(data.Expected, actual); Assert.AreEqual(data.ExpectedEnd, pos); }
public void TryReadInt() { int pos = 4; int actual; const string text = "ab 12345"; IntReader.TryReadInt32(text, ref pos, out actual); var sw = Stopwatch.StartNew(); var n = 1000000; for (int i = 0; i < n; i++) { pos = 4; IntReader.TryReadInt32(text, ref pos, out actual); } sw.Stop(); Console.WriteLine($"// {DateTime.Today.ToShortDateString()}| IntReader.TryReadInt32(\"{text}\", 4, ...) {n:N0} times {sw.ElapsedMilliseconds} ms"); sw.Restart(); string substring = null; for (int i = 0; i < n; i++) { substring = text.Substring(4); int.TryParse(substring, out actual); } sw.Stop(); Console.WriteLine($"// {DateTime.Today.ToShortDateString()}| int.TryParse(substring: \"{substring}\", ...) {n:N0} times {sw.ElapsedMilliseconds} ms"); sw.Restart(); for (int i = 0; i < n; i++) { int.TryParse(substring, out actual); } sw.Stop(); Console.WriteLine($"// {DateTime.Today.ToShortDateString()}| int.TryParse(\"{substring}\", ...) {n:N0} times {sw.ElapsedMilliseconds} ms"); }