-
Notifications
You must be signed in to change notification settings - Fork 0
/
03_minimize_length.js
84 lines (61 loc) · 2.26 KB
/
03_minimize_length.js
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
function Adjust(rectangle) {
rectangle.Size = Size.S;
rectangle.HasError = false;
rectangle.IsSquare = false;
if (rectangle.Width >= 10000) rectangle.Size = Size.L;
if (rectangle.Height <= 100) rectangle.HasError = true;
if (rectangle.Width === rectangle.Height) rectangle.IsSquare = true;
if (rectangle.Width >= 20000) rectangle.Size = Size.XL;
if (rectangle.Height <= 200) rectangle.Size = Size.M;
if (rectangle.Width <= 300) rectangle.HasError = true;
}
function Adjust_new(rectangle) {
rectangle.Size = Size.S;
rectangle.HasError = false;
rectangle.IsSquare = false;
if (rectangle.Width >= 10000) rectangle.Size = Size.L;
if (rectangle.Height <= 100) rectangle.HasError = true;
if (rectangle.Width === rectangle.Height) rectangle.IsSquare = true;
if (rectangle.Width >= 20000) rectangle.Size = Size.XL;
if (rectangle.Height <= 200) rectangle.Size = Size.M;
if (rectangle.Width <= 300) rectangle.HasError = true;
}
import fc from "fast-check";
function test() {
fc.assert(
fc.property(fc.integer(0, 30000), fc.integer(0, 30000), (width, height) => {
let rectangle = {
TotalPurchases: totalPurchases,
RecentOrders: recentOrders,
LovesJavaScript: lovesJavaScript,
KnowsCobol: knowsCobol,
};
let rectangle_expected = JSON.parse(JSON.stringify(rectangle));
Adjust(rectangle_expected);
Adjust_new(rectangle);
expect(rectangle.Size).toBe(rectangle_expected.Size);
expect(rectangle.HasError).toBe(rectangle_expected.HasError);
expect(rectangle.IsSquare).toBe(rectangle_expected.IsSquare);
})
);
}
function Adjust_new(rectangle) {
AdjustSize(rectangle);
AdjustHasError(rectangle);
AdjustIsSquare(rectangle);
}
function AdjustSize(rectangle) {
if (rectangle.Height <= 200) rectangle.Size = Size.M;
else if (rectangle.Width >= 20000) rectangle.Size = Size.XL;
else if (rectangle.Width >= 10000) rectangle.Size = Size.L;
else rectangle.Size = Size.S;
}
function AdjustHasError(rectangle) {
if (rectangle.Height <= 100 || rectangle.Width <= 300)
rectangle.HasError = true;
else rectangle.HasError = false;
}
function AdjustIsSquare(rectangle) {
if (rectangle.Width === rectangle.Height) rectangle.IsSquare = true;
else rectangle.IsSquare = false;
}