public void TestCTOR_Default() { var basicLine = new BasicLine(); Assert.AreEqual(String.Empty, basicLine.Cars); Assert.AreEqual(-1, basicLine.Index); Assert.AreEqual("the train line", basicLine.Name); }
public void TestCTOR_ParametersGood() { var basicLine = new BasicLine("0012", 2); Assert.AreEqual("12", basicLine.Cars); Assert.AreEqual(2, basicLine.Index); Assert.AreEqual("line 3", basicLine.Name); }
void WriteLine(BinaryWriter writer, Line line) { writer.Write(line.Id); writer.Write((uint)line.Type); if (line.Type == LineType.spanning) { WriteList <int>(writer, (line as SpanningLine).Blocks, delegate(BinaryWriter w, int u) { w.Write(u); }); } else { BasicLine basicLine = line as BasicLine; writer.Write(basicLine.Priority); if (basicLine is RelativeLine) { writer.Write((basicLine as RelativeLine).RelativeTo); } writer.Write(basicLine.Shape); writer.Write(basicLine.Spacing); writer.Write(basicLine.Crescent_Y_Offset); writer.Write(basicLine.X); writer.Write(basicLine.Y); writer.Write(basicLine.MinThreshold); writer.Write(basicLine.MaxThreshold); WriteList(writer, basicLine.PriorityClassPairs, WritePriorityClassPair); } }
public void TestCTOR_MoveTwoPartsGood() { var basicLine = new BasicLine("0012233", 2); var basicLine2 = new BasicLine("00222", 3); basicLine.Move(basicLine2, 5); Assert.AreEqual("33122222", basicLine2.Cars); Assert.AreEqual("", basicLine.Cars); }
public void TestCTOR_MoveGood() { var basicLine = new BasicLine("0012", 2); var basicLine2 = new BasicLine("00222", 3); basicLine.Move(basicLine2, 2); Assert.AreEqual("12222", basicLine2.Cars); Assert.AreEqual("", basicLine.Cars); }
public void BindTo(object o) { if (o == null) { Button.Checked = false; Button.Enabled = false; } else { Line = (BasicLine)o; Button.Checked = Line.Shape == Shape; Button.Enabled = true; } }
// create the extension of the given line RectangleF GetRectangle(Line line) { //Console.WriteLine("retrieving rect for {0}", line.Id); if (basicLines.ContainsKey(line)) { return(basicLines[line]); } else if (spanningLines.ContainsKey(line)) { return(spanningLines[line]); } RectangleF result = new RectangleF(0, 0, ItemSize, ItemSize); if (line is RelativeLine) { BasicLine thisLine = line as RelativeLine; Line relativeTo = formation.Lines[(int)(line as RelativeLine).RelativeTo]; RectangleF relationRect = GetRectangle(relativeTo); result.X = (relationRect.X + thisLine.X - Math.Sign(thisLine.X) * ItemSize); //if (thisLine.Y == 0) { result.X += (relationRect.Width - ItemSize) / 2; //} result.Y = (relationRect.Y + thisLine.Y - Math.Sign(thisLine.Y) * ItemSize); //if (thisLine.X == 0) { result.Y += (relationRect.Height - ItemSize) / 2; //} basicLines.Add(line, result); } else if (line is SpanningLine) { SpanningLine sl = line as SpanningLine; formation.Lines.ForEach(l => { if (sl.Blocks.Contains(l.Id)) { result = RectangleF.Union(result, GetRectangle(l)); } }); spanningLines.Add(line, result); //result = new Rectangle(minX, minY, Math.Abs(maxX - minX), Math.Abs(maxY - minY)); } else { BasicLine baseLine = line as BasicLine; result = new RectangleF(baseLine.X, baseLine.Y, ItemSize, ItemSize); basicLines.Add(line, result); } //Console.WriteLine("rect for {1} is {0}", result, line.Id); return(result); }
public static async Task <BasicLine[]> ReadAsync(Stream input) { List <BasicLine> lines = new List <BasicLine>(); using (StreamReader reader = new StreamReader(input)) { string line; do { line = await reader.ReadLineAsync(); if (line != null) { lines.Add(BasicLine.FromString(line)); } }while (line != null); } return(lines.ToArray()); }
public BasicLine <decimal?> GetSalesPerStore(int initialYear, int endYear) { BasicLine <decimal?> chart = new BasicLine <decimal?>(); DAL.SalesPerStore[] query = repo.GetSalesPerStore(initialYear, endYear); string[] stores = GetStoreList(query); //Getting the list of years int[] years = query .OrderBy(r => r.Year) .Select(r => r.Year) .Distinct().ToArray(); chart.PointStart = years.FirstOrDefault(); foreach (var store in stores) { Serie <decimal?> serie = new Serie <decimal?>() { Name = store, Data = new decimal?[years.Length] }; for (int i = 0; i < years.Length; i++) { decimal?value = query .Where(r => r.Year == years[i] && r.Store == store) .Select(r => r.Total) .FirstOrDefault(); serie.Data[i] = value; } chart.Series.Add(serie); } return(chart); }
Line ReadLine(BinaryReader reader) { Line line; int id = reader.ReadInt32(); LineType lineType = (LineType)reader.ReadUInt32(); //Console.WriteLine("reading line type {0} at {1}", lineType, reader.BaseStream.Position); if (lineType == LineType.spanning) { line = new SpanningLine { Blocks = ReadList <int>(reader, delegate(BinaryReader r) { return(r.ReadInt32()); }) }; } else if (lineType == LineType.absolute || lineType == LineType.relative) { BasicLine basicLine = (lineType == LineType.absolute) ? new BasicLine() : new RelativeLine(); basicLine.Priority = reader.ReadSingle(); if (lineType == LineType.relative) { (basicLine as RelativeLine).RelativeTo = reader.ReadUInt32(); } basicLine.Shape = reader.ReadInt32(); basicLine.Spacing = reader.ReadSingle(); basicLine.Crescent_Y_Offset = reader.ReadSingle(); basicLine.X = reader.ReadSingle(); basicLine.Y = reader.ReadSingle(); basicLine.MinThreshold = reader.ReadInt32(); basicLine.MaxThreshold = reader.ReadInt32(); basicLine.PriorityClassPairs = ReadList <PriorityClassPair>(reader, ReadPriorityClassPair); line = basicLine; } else { throw new InvalidDataException("unknown line type " + lineType); } line.Id = id; return(line); }
public void TestCTOR_ParametersWrong() { var basicLine = new BasicLine("0123456789A"); }
public void Invalid(string input) { Action act = () => BasicLine.FromString(input); act.Should().Throw <FormatException>("[{0}]", input).WithMessage("*'" + input + "'*").WithInnerException <Exception>(); }
public void Valid(string input, string output) { BasicLine.FromString(input).ToString().Should().Be(output, "[{0}]", input); }
// constructs BASIC program based on supplied options static void BuildBasic() { var line = new BasicLine(); // colours if (_border >= 0) { line.AddStatement(Token.Border, _border); } if (_paper >= 0) { line.AddStatement(Token.Paper, _paper); } if (_ink >= 0) { line.AddStatement(Token.Ink, _ink); } if (_bright >= 0) { line.AddStatement(Token.Bright, _bright); } // memory line.AddStatement(Token.Clear, _clear); // messages if (_printBottom.Count > 0) { line.AddStatement(Token.Lprint, (byte)'#', 0 /*1*/, (byte)';', _printBottom); } if (_printTop.Count > 0) { line.AddStatement(Token.Print, _printTop); } // jump address (start of BASIC) const string startOfBasic = "\x00be23635+256*\x00be23636"; line.AddStatement(Token.Randomize, Token.Usr, Token.Val, startOfBasic); // optional pause if (_pause >= 0) { line.AddStatement(Token.Pause, _pause); } _data.AddRange(line); // if additional jump addresses specified, add them on their own // lines foreach (var tuple in _usr) { line = new BasicLine(); if (tuple.Item1 > 0) { line.AddStatement(Token.Clear, tuple.Item1); } line.AddStatement(Token.Randomize, Token.Usr, tuple.Item2); _data.AddRange(line); } }