public void ParseError(ErrorData <int> data) { int pos = data.Start; Assert.Throws <FormatException>(() => IntReader.ReadInt32(data.Text, ref pos)); Assert.AreEqual(pos, data.ExpectedEnd); }
public void ParseError(ErrorCase <int> @case) { int pos = @case.Start; Assert.Throws <FormatException>(() => IntReader.ReadInt32(@case.Text, ref pos)); Assert.AreEqual(pos, @case.ExpectedEnd); }
public void ParseSuccess(SuccessCase <int> data) { int pos = data.Start; var actual = IntReader.ReadInt32(data.Text, ref pos); Assert.AreEqual(actual, data.Expected); Assert.AreEqual(pos, data.ExpectedEnd); }
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 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); }
private static bool TryReadPrefixNumberFormat(string format, ref int pos, out string result) { var start = pos; pos++; _ = IntReader.TrySkipDigits(format, ref pos); result = format.Substring(start, pos - start); return(true); }
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); }
/// <summary>Translates bytes to ints.</summary> /// <remarks> /// Translates bytes to ints. /// NB: intLen == 4 * byteSize! /// NB: intLen should be less or equal to intBuffer length. /// </remarks> internal static void Convert(IntReader ir, int intLen) { for (int i = 0; i < intLen; ++i) { ir.intBuffer[i] = (ir.byteBuffer[i * 4] & 0xFF) | ((ir.byteBuffer[(i * 4) + 1] & 0xFF) << 8) | ((ir.byteBuffer[(i * 4) + 2] & 0xFF) << 16) | ((ir.byteBuffer[(i * 4) + 3] & 0xFF) << 24); } }
public void Run() { DecimalReader decReader = new DecimalReader(); IntReader intReader = new IntReader(); decimal costOfPowerPerWStation = decReader.ReadRange("Введiть вартiсть пiдключення живлення на одну робочу станцiю вiд {0} до {1}: ", 10, 10000); decimal costOfInternetPerWStation = decReader.ReadRange("Введiть вартiсть пiдключення iнтернету на одну робочу станцiю вiд {0} до {1}: ", 10, 10000); decimal numberOfWStation = intReader.ReadRange("Введiть число робочих станцiй вiд {0} до {1}: ", 1, 100); //калькуляцiя заходу decimal costOfAccess = (costOfInternetPerWStation + costOfPowerPerWStation) * numberOfWStation; //виведення результату Console.WriteLine("Загальна вартiсть заходу: {0}", costOfAccess); }
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"); }
// Add some non-zero constants to the mix. public void AddConstantsToTDB(RandoopConfiguration config) { foreach (SimpleTypeValues vs in config.simpleTypeValues) { Type type = Type.GetType(vs.simpleType); if (type == null) { throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file."); } foreach (FileName fn in vs.fileNames) { string fileName = fn.fileName; if (!File.Exists(fileName)) { throw new Common.RandoopBareExceptions.InvalidUserParamsException("Configuration file does not exist: " + fileName); } if (type.Equals(typeof(sbyte))) { SByteReader r = new SByteReader(); foreach (object o in r.Read(fileName)) { this.AddPlan(Plan.Constant(typeof(sbyte), o)); } } else if (type.Equals(typeof(byte))) { ByteReader r = new ByteReader(); foreach (object o in r.Read(fileName)) { this.AddPlan(Plan.Constant(typeof(byte), o)); } } else if (type.Equals(typeof(short))) { ShortReader r = new ShortReader(); foreach (object o in r.Read(fileName)) { this.AddPlan(Plan.Constant(typeof(short), o)); } } else if (type.Equals(typeof(ushort))) { UshortReader r = new UshortReader(); foreach (object o in r.Read(fileName)) { this.AddPlan(Plan.Constant(typeof(ushort), o)); } } else if (type.Equals(typeof(int))) { IntReader r = new IntReader(); foreach (object o in r.Read(fileName)) { this.AddPlan(Plan.Constant(typeof(int), o)); } } else if (type.Equals(typeof(uint))) { UintReader r = new UintReader(); foreach (object o in r.Read(fileName)) { this.AddPlan(Plan.Constant(typeof(uint), o)); } } else if (type.Equals(typeof(long))) { LongReader r = new LongReader(); foreach (object o in r.Read(fileName)) { this.AddPlan(Plan.Constant(typeof(long), o)); } } else if (type.Equals(typeof(ulong))) { UlongReader r = new UlongReader(); foreach (object o in r.Read(fileName)) { this.AddPlan(Plan.Constant(typeof(ulong), o)); } } else if (type.Equals(typeof(char))) { CharReader r = new CharReader(); foreach (object o in r.Read(fileName)) { this.AddPlan(Plan.Constant(typeof(char), o)); } } else if (type.Equals(typeof(float))) { FloatReader r = new FloatReader(); foreach (object o in r.Read(fileName)) { this.AddPlan(Plan.Constant(typeof(float), o)); } } else if (type.Equals(typeof(double))) { DoubleReader r = new DoubleReader(); foreach (object o in r.Read(fileName)) { this.AddPlan(Plan.Constant(typeof(double), o)); } } else if (type.Equals(typeof(bool))) { BoolReader r = new BoolReader(); foreach (object o in r.Read(fileName)) { this.AddPlan(Plan.Constant(typeof(bool), o)); } } else if (type.Equals(typeof(decimal))) { DecimalReader r = new DecimalReader(); foreach (object o in r.Read(fileName)) { this.AddPlan(Plan.Constant(typeof(decimal), o)); } } else { if (!type.Equals(typeof(string))) { throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file."); } Common.StringReader r = new Common.StringReader(); foreach (object o in r.Read(fileName)) { this.AddPlan(Plan.Constant(typeof(string), o)); } } } } }
// Add some non-zero constants to the mix. public void AddConstantsToTDB(RandoopConfiguration config) { foreach (SimpleTypeValues vs in config.simpleTypeValues) { Type type = Type.GetType(vs.simpleType); if (type == null) { throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file."); } foreach (FileName fn in vs.fileNames) { string fileName = fn.fileName; if (!File.Exists(fileName)) { throw new Common.RandoopBareExceptions.InvalidUserParamsException("Configuration file does not exist: " + fileName); } if (type.Equals(typeof(sbyte))) { SByteReader r = new SByteReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(sbyte), o)); } else if (type.Equals(typeof(byte))) { ByteReader r = new ByteReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(byte), o)); } else if (type.Equals(typeof(short))) { ShortReader r = new ShortReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(short), o)); } else if (type.Equals(typeof(ushort))) { UshortReader r = new UshortReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(ushort), o)); } else if (type.Equals(typeof(int))) { IntReader r = new IntReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(int), o)); } else if (type.Equals(typeof(uint))) { UintReader r = new UintReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(uint), o)); } else if (type.Equals(typeof(long))) { LongReader r = new LongReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(long), o)); } else if (type.Equals(typeof(ulong))) { UlongReader r = new UlongReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(ulong), o)); } else if (type.Equals(typeof(char))) { CharReader r = new CharReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(char), o)); } else if (type.Equals(typeof(float))) { FloatReader r = new FloatReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(float), o)); } else if (type.Equals(typeof(double))) { DoubleReader r = new DoubleReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(double), o)); } else if (type.Equals(typeof(bool))) { BoolReader r = new BoolReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(bool), o)); } else if (type.Equals(typeof(decimal))) { DecimalReader r = new DecimalReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(decimal), o)); } else { if (!type.Equals(typeof(string))) { throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file."); } Common.StringReader r = new Common.StringReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(string), o)); } } } }
internal static void Init(IntReader ir, byte[] byteBuffer, int[] intBuffer) { ir.byteBuffer = byteBuffer; ir.intBuffer = intBuffer; }