-
Notifications
You must be signed in to change notification settings - Fork 5k
/
Program.cs
128 lines (112 loc) · 5.52 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using CommercialRegistration;
using ConsumerVehicleRegistration;
using LiveryRegistration;
namespace toll_calculator
{
class Program
{
static void Main(string[] args)
{
/* First set of test code
var tollCalc = new TollCalculator();
var car = new Car();
var taxi = new Taxi();
var bus = new Bus();
var truck = new DeliveryTruck();
Console.WriteLine($"The toll for a car is {tollCalc.CalculateToll(car)}");
Console.WriteLine($"The toll for a taxi is {tollCalc.CalculateToll(taxi)}");
Console.WriteLine($"The toll for a bus is {tollCalc.CalculateToll(bus)}");
Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(truck)}");
try
{
tollCalc.CalculateToll("this will fail");
}
catch (ArgumentException e)
{
Console.WriteLine("Caught an argument exception when using the wrong type");
}
try
{
tollCalc.CalculateToll(null);
}
catch (ArgumentNullException e)
{
Console.WriteLine("Caught an argument exception when using null");
}
*/
/* 2nd test (after adding for occupants)
var tollCalc = new TollCalculator();
var soloDriver = new Car();
var twoRideShare = new Car { Passengers = 1 };
var threeRideShare = new Car { Passengers = 2 };
var fullVan = new Car { Passengers = 5 };
var emptyTaxi = new Taxi();
var singleFare = new Taxi { Fares = 1 };
var doubleFare = new Taxi { Fares = 2 };
var fullVanPool = new Taxi { Fares = 5 };
var lowOccupantBus = new Bus { Capacity = 90, Riders = 15 };
var normalBus = new Bus { Capacity = 90, Riders = 75 };
var fullBus = new Bus { Capacity = 90, Riders = 85 };
var heavyTruck = new DeliveryTruck { GrossWeightClass = 7500 };
var truck = new DeliveryTruck { GrossWeightClass = 4000 };
var lightTruck = new DeliveryTruck { GrossWeightClass = 2500 };
Console.WriteLine($"The toll for a solo driver is {tollCalc.CalculateToll(soloDriver)}");
Console.WriteLine($"The toll for a two ride share is {tollCalc.CalculateToll(twoRideShare)}");
Console.WriteLine($"The toll for a three ride share is {tollCalc.CalculateToll(threeRideShare)}");
Console.WriteLine($"The toll for a fullVan is {tollCalc.CalculateToll(fullVan)}");
Console.WriteLine($"The toll for an empty taxi is {tollCalc.CalculateToll(emptyTaxi)}");
Console.WriteLine($"The toll for a single fare taxi is {tollCalc.CalculateToll(singleFare)}");
Console.WriteLine($"The toll for a double fare taxi is {tollCalc.CalculateToll(doubleFare)}");
Console.WriteLine($"The toll for a full van taxi is {tollCalc.CalculateToll(fullVanPool)}");
Console.WriteLine($"The toll for a low-occupant bus is {tollCalc.CalculateToll(lowOccupantBus)}");
Console.WriteLine($"The toll for a regular bus is {tollCalc.CalculateToll(normalBus)}");
Console.WriteLine($"The toll for a bus is {tollCalc.CalculateToll(fullBus)}");
Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(heavyTruck)}");
Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(truck)}");
Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(lightTruck)}");
try
{
tollCalc.CalculateToll("this will fail");
}
catch (ArgumentException e)
{
Console.WriteLine("Caught an argument exception when using the wrong type");
}
try
{
tollCalc.CalculateToll(null);
}
catch (ArgumentNullException e)
{
Console.WriteLine("Caught an argument exception when using null");
}
*/
/*
Console.WriteLine("Testing the time premiums");
var testTimes = new DateTime[]
{
new DateTime(2019, 3, 4, 8, 0, 0), // morning rush
new DateTime(2019, 3, 6, 11, 30, 0), // daytime
new DateTime(2019, 3, 7, 17, 15, 0), // evening rush
new DateTime(2019, 3, 14, 03, 30, 0), // overnight
new DateTime(2019, 3, 16, 8, 30, 0), // weekend morning rush
new DateTime(2019, 3, 17, 14, 30, 0), // weekend daytime
new DateTime(2019, 3, 17, 18, 05, 0), // weekend evening rush
new DateTime(2019, 3, 16, 01, 30, 0), // weekend overnight
};
foreach (var time in testTimes)
{
Console.WriteLine($"Inbound premium at {time} is {tollCalc.PeakTimePremiumFull(time, true)}");
Console.WriteLine($"Outbound premium at {time} is {tollCalc.PeakTimePremiumFull(time, false)}");
}
Console.WriteLine("====================================================");
foreach (var time in testTimes)
{
Console.WriteLine($"Inbound premium at {time} is {tollCalc.PeakTimePremium(time, true)}");
Console.WriteLine($"Outbound premium at {time} is {tollCalc.PeakTimePremium(time, false)}");
}
*/
}
}
}