-
Notifications
You must be signed in to change notification settings - Fork 0
/
SquarePaving.cs
150 lines (121 loc) · 4.93 KB
/
SquarePaving.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
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace PrimitiveTypes
{
[TestClass]
public class SquarePaving
{
[TestMethod]
[TestCategory("01_Square_Paving")]
public void Compute_Bricks_Needed_When_BrickSide_Is_Bigger_Than_Field_Length_Or_With() {
int fieldLength = 3;
int fieldWidth = 6;
int brickSideLengh = 8;
int expectedResult = 1;
int result = ComputeNeededBricks(fieldLength, fieldWidth, brickSideLengh);
Assert.AreEqual(expectedResult, result);
}
[TestMethod]
[TestCategory("01_Square_Paving")]
public void Compute_Bricks_Needed_When_BrickSide_Is_Bigger_Than_Field_Length() {
int fieldLength = 3;
int fieldWidth = 6;
int brickSideLengh = 4;
int expectedResult = 2;
int result = ComputeNeededBricks(fieldLength, fieldWidth, brickSideLengh);
Assert.AreEqual(expectedResult, result);
}
[TestMethod]
[TestCategory("01_Square_Paving")]
public void Compute_Bricks_Needed_When_BrickSide_Is_Smaller_Than_Field_Length_Or_Width() {
int fieldLength = 6;
int fieldWidth = 6;
int brickSideLengh = 4;
int expectedResult = 4;
int result = ComputeNeededBricks(fieldLength, fieldWidth, brickSideLengh);
Assert.AreEqual(expectedResult, result);
}
[TestMethod]
[TestCategory("01_Square_Paving")]
public void Compute_Bricks_Needed_When_BrickSide_Is_Exact_Multiple_For_Field_Length_Or_Width() {
int fieldLength = 8;
int fieldWidth = 8;
int brickSideLengh = 2;
int expectedResult = 16;
int result = ComputeNeededBricks(fieldLength, fieldWidth, brickSideLengh);
Assert.AreEqual(expectedResult, result);
}
[TestMethod]
[TestCategory("01_Square_Paving")]
public void Compute_Bricks_Needed_When_BrickSide_Is_Zero() {
int fieldLength = 3;
int fieldWidth = 6;
int brickSideLengh = 0;
int expectedResult = 0;
int result = ComputeNeededBricks(fieldLength, fieldWidth, brickSideLengh);
Assert.AreEqual(expectedResult, result);
}
[TestMethod]
[TestCategory("01_Square_Paving")]
public void Compute_Bricks_Needed_When_FieldLength_Is_Zero() {
int fieldLength = 0;
int fieldWidth = 6;
int brickSideLengh = 4;
int expectedResult = 0;
int result = ComputeNeededBricks(fieldLength, fieldWidth, brickSideLengh);
Assert.AreEqual(expectedResult, result);
}
[TestMethod]
[TestCategory("01_Square_Paving")]
public void Compute_Bricks_Needed_When_FieldWidth_Is_Zero() {
int fieldLength = 0;
int fieldWidth = 0;
int brickSideLengh = 4;
int expectedResult = 0;
int result = ComputeNeededBricks(fieldLength, fieldWidth, brickSideLengh);
Assert.AreEqual(expectedResult, result);
}
[TestMethod]
[TestCategory("01_Square_Paving")]
public void Compute_Bricks_Needed_When_All_Input_Values_Are_Zero() {
int fieldLength = 0;
int fieldWidth = 0;
int brickSideLengh = 0;
int expectedResult = 0;
int result = ComputeNeededBricks(fieldLength, fieldWidth, brickSideLengh);
Assert.AreEqual(expectedResult, result);
}
[TestMethod]
[TestCategory("01_Square_Paving")]
public void Compute_Bricks_Needed_When_All_Input_Values_Are_Negative() {
int fieldLength = -1;
int fieldWidth = -1;
int brickSideLengh = -1;
int expectedResult = 0;
int result = ComputeNeededBricks(fieldLength, fieldWidth, brickSideLengh);
Assert.AreEqual(expectedResult, result);
}
private int ComputeNeededBricks(int fieldLength, int fieldWidth, int brickSideLengh) {
int briksOnLength = ComputeBricksOnSide(fieldLength,brickSideLengh);
int bricksOnWith = ComputeBricksOnSide(fieldWidth, brickSideLengh);
return briksOnLength * bricksOnWith;
}
private static int ComputeBricksOnSide(int sideSize, int brickSideSize) {
if (sideSize < brickSideSize && sideSize > 0) {
return 1;
} else {
if (sideSize == 0) {
return 0;
} else if (brickSideSize > 0) {
if (sideSize % brickSideSize == 0) {
return sideSize / brickSideSize;
} else {
return (sideSize / brickSideSize) + 1;
}
} else {
return 0;
}
}
}
}
}