-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUnitTest.cs
225 lines (183 loc) · 5.05 KB
/
UnitTest.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
using EasyCBR.Enums;
using EasyCBR.Helpers;
using EasyCBR.SimilarityFunctions;
namespace EasyCBR.Tests.UnitTests;
//ToDo Rename the methods
public class UnitTest
{
public List<Order> orders = new List<Order>()
{
new Order(1, "Osama", OrderType.A, 100),
new Order(2, "Mohammed", OrderType.C, 120),
new Order(3, "Hussam", OrderType.B, 430),
new Order(4, "Mohanned", OrderType.B, 90),
new Order(5, "Abd Alqader", OrderType.A, 5)
};
[Fact]
public void Test1()
{
//Arrange
var cbr = CBR<Order, decimal>.Create(orders);
//Act
var expected = 5;
//Assert
Assert.Equal(cbr.Cases.Count, expected);
}
[Fact]
public void Test2()
{
//Arrange
var create = CBR<Order, decimal>.Create;
//Act
//Assert
Assert.Throws<ArgumentNullException>(() => create(null));
}
[Fact]
public void Test3()
{
//Arrange
var create = CBR<Order, decimal>.Create;
//Act
//Assert
Assert.Throws<ArgumentOutOfRangeException>(() => create(new List<Order>()));
}
[Fact]
public void Test4()
{
//Arrange
var cbr = CBR<Order, decimal>.Create(orders).Output(x => x.Price);
//Act
var expected = nameof(Order.Price);
//Assert
Assert.Equal(cbr.Output.Name, expected);
}
[Fact]
public void Test5()
{
//Arrange
var cbr = CBR<Order, decimal>
.Create(orders)
.Output(x => x.Price)
.SetSimilarityFunctions((nameof(Order.CustomerName), new BasicSimilarityFunction<string>()));
//Act
//Assert
Assert.True(true);
}
[Fact]
public void Test6()
{
//Arrange
//Act
//Assert
Assert.Throws<ArgumentException>(() => CBR<Order, decimal>
.Create(orders)
.Output(x => x.Price)
.SetSimilarityFunctions());
}
[Fact]
public void Test7()
{
//Arrange
//Act
//Assert
Assert.Throws<ArgumentNullException>(() => CBR<Order, decimal>
.Create(orders)
.Output(x => x.Price)
.SetSimilarityFunctions(null));
}
[Fact]
public void Test8()
{
//Arrange
//Act
//Assert
Assert.Throws<ArgumentException>(() => CBR<Order, decimal>
.Create(orders)
.Output(x => x.Price)
.SetSimilarityFunctions(
("test", new BasicSimilarityFunction<string>())
));
}
[Fact]
public void Test9()
{
//Arrange
//Act
//Assert
Assert.Throws<ArgumentException>(() => CBR<Order, decimal>
.Create(orders)
.Output(x => x.Price)
.SetSimilarityFunctions(
(nameof(Order.Id), new BasicSimilarityFunction<string>())
));
}
[Fact]
public void Test10()
{
//Arrange
var cbr = CBR<Order, decimal>
.Create(orders)
.Output(x => x.Price)
.SetSimilarityFunctions(
(nameof(Order.CustomerName), new BasicSimilarityFunction<string>())
).Retrieve(new Order(6, "test", OrderType.A, 0), 2);
//Act
//Assert
Assert.True(cbr.Run().Count == 2);
}
[Fact]
public void Test11()
{
//Arrange
//Act
//Assert
Assert.Throws<ArgumentNullException>(() => CBR<Order, decimal>
.Create(orders)
.Output(x => x.Price)
.SetSimilarityFunctions(
(nameof(Order.CustomerName), new BasicSimilarityFunction<string>())
).Retrieve(null, 2));
}
[Fact]
public void Test12()
{
//Arrange
//Act
//Assert
Assert.Throws<ArgumentOutOfRangeException>(() => CBR<Order, decimal>
.Create(orders)
.Output(x => x.Price)
.SetSimilarityFunctions(
(nameof(Order.CustomerName), new BasicSimilarityFunction<string>())
).Retrieve(new Order(6, "test", OrderType.A, 0), 0));
}
[Fact]
public void Test13()
{
//Arrange
var cbr = CBR<Order, decimal>
.Create(orders)
.Output(x => x.Price)
.SetSimilarityFunctions(
(nameof(Order.CustomerName), new BasicSimilarityFunction<string>())
).Retrieve(new Order(6, "test", OrderType.A, 0), 2)
.Reuse();
//Act
//Assert
Assert.True(cbr.Run() is not null);
}
[Fact]
public void Test14()
{
//Arrange
//Act
//Assert
Assert.Throws<ArgumentOutOfRangeException>(() => CBR<Order, decimal>
.Create(orders)
.Output(x => x.Price)
.SetSimilarityFunctions(
(nameof(Order.CustomerName), new BasicSimilarityFunction<string>())
).Retrieve(new Order(6, "test", OrderType.A, 0), 2)
.Reuse((SelectType)10));
}
}