static void Main(string[] args) { ApplicationUtilities.DisplayApplicationInformation(); ApplicationUtilities.DisplayDivider("Program Start"); Racer[] racerList = new Racer[2]; racerList[0] = new HotRod(); racerList[1] = new StreetTuner(); for (int i = 0; i < 2; i++ ) { if (racerList[i] is HotRod) { RacerInput.CollectHotRodInformation((HotRod)racerList[i]); RacerOutput.DisplayHotRodInformation((HotRod)racerList[i]); } else if (racerList[i] is StreetTuner) { RacerInput.CollectStreetTunerInformation((StreetTuner)racerList[i]); RacerOutput.DisplayStreetTunerInformation((StreetTuner)racerList[i]); } else break; } ApplicationUtilities.TerminateApplication(); }
//method to display Street Tuner output to user public static void DisplayStreetTunerInformation(Racer anotherRacer) { ApplicationUtilities.DisplayDivider("Street Tuner"); ApplicationUtilities.DisplayDivider("Street Tuner Information"); Console.WriteLine(); Console.WriteLine(anotherRacer.ToString()); ApplicationUtilities.PauseExecution(); }
//method to display Hot Rod output to user public static void DisplayHotRodInformation(Racer theRacer) { ApplicationUtilities.DisplayDivider("Hot Rod"); ApplicationUtilities.DisplayDivider("Hot Rod Information"); Console.WriteLine(); Console.WriteLine(theRacer.ToString()); ApplicationUtilities.PauseExecution(); }
public void TestSubscribe() { Racer.Racer r = new Racer.Racer("Drew", "Torgeson", 1, 1); RacerObserver observer = new RacerObserver(); r.Subscribe(observer); Assert.That(r.Observers.Contains(observer), Is.True); Assert.DoesNotThrow(() => r.Subscribe(null)); }
public void TestUpdateLocation() { Racer.Racer r = new Racer.Racer("Drew", "Torgeson", 1, 1); int location = 5; DateTime time = DateTime.Now; r.UpdateLocation(5, time); Assert.That(r.Location, Is.EqualTo(location)); Assert.That(r.LastSeen, Is.EqualTo(time)); }
public void TestUpdate() { Racer.Racer r = new Racer.Racer("Drew", "Torgeson", 1, 1); RacerObserver observer = new RacerObserver(); observer.Update(r); Assert.That(observer.Racers[r.Bib], Is.EqualTo(r)); Assert.DoesNotThrow(() => observer.Update(null)); r.GroupID = 2; observer.Update(r); Assert.That(observer.Racers[r.Bib].GroupID, Is.EqualTo(r.GroupID)); }
private void DetectCheating(Racer racer) { foreach (Racer other in currentPositions.Values) { Racer prevRacer, prevOther; if (lastPositions.TryGetValue(other.Bib, out prevOther) && lastPositions.TryGetValue(racer.Bib, out prevRacer)) if (AreCheating(racer, other, prevRacer, prevOther)) { lock(Lock) { cheaters.Add(racer.Bib, racer); cheaters.Add(other.Bib, other); } } } }
public void TestAddRacer() { RaceGroup group = new RaceGroup(1, "TestGroup", 0, 100, DateTime.Now); Assert.DoesNotThrow(() => group.AddRacer(null)); Racer.Racer r = new Racer.Racer("Drew", "Torgeson", 0, group.ID); group.AddRacer(r); Assert.That(group.Racers[0], Is.EqualTo(r)); Racer.Racer r1 = new Racer.Racer("Drew", "Torgeson", 0, group.ID); group.AddRacer(r1); Assert.That(group.Racers[0], Is.EqualTo(r)); for (int i = 1; i < 99; i++) group.AddRacer(new Racer.Racer("Drew", "Torgeson", i, group.ID)); Racer.Racer r2 = new Racer.Racer("Drew", "Torgeson", 1000, group.ID); group.AddRacer(r2); Assert.That(group.Racers.TryGetValue(1000, out r2), Is.False); Racer.Racer r3 = new Racer.Racer("Drew", "Torgeson", 1000, group.ID); group.AddRacer(r3); Assert.That(group.Racers.TryGetValue(-1000, out r3), Is.False); Racer.Racer r4 = new Racer.Racer("Drew", "Torgeson", 99, group.ID - 1); group.AddRacer(r4); Assert.That(group.Racers.TryGetValue(99, out r4), Is.False); group.AddRacer(new Racer.Racer("Drew", "Torgeson", 99, group.ID)); group.AddRacer(new Racer.Racer("Drew", "Torgeson", 100, group.ID)); group.AddRacer(new Racer.Racer("Drew", "Torgeson", 101, group.ID)); Assert.That(group.Racers.TryGetValue(100, out r4), Is.False); Assert.That(group.Racers.TryGetValue(101, out r4), Is.False); }
public void TestRemove() { Racer.Racer r1 = new Racer.Racer("Drew", "Torgeson", 1, 1); Racer.Racer r2 = new Racer.Racer("Drew", "Torgeson", 2, 1); Racer.Racer r3 = new Racer.Racer("Drew", "Torgeson", 3, 1); Racer.Racer r4 = new Racer.Racer("Drew", "Torgeson", 4, 1); RacerObserver observer = new RacerObserver(); observer.Racers.Add(r1.Bib, r1); observer.Racers.Add(r2.Bib, r2); observer.Racers.Add(r3.Bib, r3); observer.Remove(r4); Assert.That(observer.Racers.Count, Is.EqualTo(3)); Assert.That(observer.Racers.ContainsValue(r4), Is.EqualTo(false)); observer.Remove(r3); Assert.That(observer.Racers.Count, Is.EqualTo(2)); Assert.That(observer.Racers.ContainsValue(r3), Is.EqualTo(false)); Assert.DoesNotThrow(() => observer.Remove(null)); }
public void TestNotCheatersLocation() { CheatingDetector detector = new CheatingDetector("Test"); Racer.Racer prevRacer = new Racer.Racer("Test", "Test", 1, 1); prevRacer.Location = 10; prevRacer.LastSeen = DateTime.Now; Racer.Racer prevRacer2 = new Racer.Racer("Test", "Test", 1, 2); prevRacer2.Location = 10; prevRacer2.LastSeen = DateTime.Now; Racer.Racer r = new Racer.Racer("Test", "Test", 1, 1); Racer.Racer r2 = new Racer.Racer("Test", "Test", 1, 2); r.Location = 15; r2.Location = 16; r.LastSeen = prevRacer.LastSeen + TimeSpan.FromSeconds(2); r2.LastSeen = prevRacer.LastSeen + TimeSpan.FromSeconds(3); Assert.That(detector.AreCheating(r, r2, prevRacer, prevRacer2), Is.False); }
public bool AreCheating(Racer racer, Racer other, Racer prevRacer, Racer prevOther) { return (other.GroupID != racer.GroupID && other.Location == racer.Location && prevOther.Location == prevRacer.Location && Math.Abs((other.LastSeen - racer.LastSeen).Seconds) < TIME_BUFFER && Math.Abs((prevOther.LastSeen - prevRacer.LastSeen).Seconds) < TIME_BUFFER); }
public void Update(Racer r) { if (r != null) repaintNeeded = true; }
private Dictionary<int, Racer> ReadRacers(string filename) { Dictionary<int, Racer> racers = new Dictionary<int, Racer>(); using (StreamReader reader = File.OpenText(filename)) { string all = reader.ReadToEnd(); foreach (var line in all.Split('\n')) { if (line != "") { string[] pieces = line.Split(','); int groupId, bib; if (!Int32.TryParse(pieces[2], out bib)) throw new FormatException("Expected integer bib number but found non-integer value"); if (!Int32.TryParse(pieces[3], out groupId)) throw new FormatException("Expected integer group id but found non-integer value"); string first = pieces[0]; string last = pieces[1]; Racer racer = new Racer(first, last, bib, groupId); if (!racers.ContainsKey(bib)) { racers.Add(bib, racer); Groups[groupId].AddRacer(racer); } } } } return racers; }
public void AddRacer(Racer r) { if (r != null && Racers.Count < MAX_RACERS && BlockMin <= r.Bib && r.Bib <= BlockMax && !Racers.ContainsKey(r.Bib) && r.GroupID == ID) Racers.Add(r.Bib, r); }