-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMushrooms.cs
99 lines (79 loc) · 3.86 KB
/
Mushrooms.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
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace PrimitiveTypes
{
[TestClass]
public class Mushrooms
{
[TestMethod]
[TestCategory("09_Mushrooms_Count")]
public void Count_Mushrooms_When_Multiplication_Factor_Is_Negative() {
Tuple<int, int> actualCount = new Tuple<int, int>(-1, -1);
int totalMushrooms = 1;
int multilicationFactor = -5;
Tuple<int, int> mushroomsCounted = CountMushrooms(totalMushrooms, multilicationFactor);
Assert.AreEqual(mushroomsCounted, actualCount);
}
[TestMethod]
[TestCategory("09_Mushrooms_Count")]
public void Count_Mushrooms_When_Total_Mushrooms_And_Multiplication_Factor_Is_Zero() {
Tuple<int, int> actualCount = new Tuple<int, int>(-1, -1);
int totalMushrooms = 0;
int multilicationFactor = 0;
Tuple<int, int> mushroomsCounted = CountMushrooms(totalMushrooms, multilicationFactor);
Assert.AreEqual(mushroomsCounted, actualCount);
}
[TestMethod]
[TestCategory("09_Mushrooms_Count")]
public void Count_Mushrooms_When_Total_Mushrooms_Is_Zero() {
Tuple<int, int> actualCount = new Tuple<int, int>(-1, -1);
int totalMushrooms = 0;
int multilicationFactor = 4;
Tuple<int, int> mushroomsCounted = CountMushrooms(totalMushrooms, multilicationFactor);
Assert.AreEqual(mushroomsCounted, actualCount);
}
[TestMethod]
[TestCategory("09_Mushrooms_Count")]
public void Count_Mushrooms_When_Multiplication_Factor_Determins_Division_With_Remainder()
{
Tuple<int, int> actualCount = new Tuple<int, int>(-1, -1);
int totalMushrooms = 8;
int multilicationFactor = 4;
Tuple<int, int> mushroomsCounted = CountMushrooms(totalMushrooms, multilicationFactor);
Assert.AreEqual(mushroomsCounted, actualCount);
}
[TestMethod]
[TestCategory("09_Mushrooms_Count")]
public void Count_Mushrooms_When_Multiplication_Factor_Is_Zero() {
Tuple<int, int> actualCount = new Tuple<int, int>(-1, -1);
int totalMushrooms = 9;
int multilicationFactor = 0;
Tuple<int, int> mushroomsCounted = CountMushrooms(totalMushrooms, multilicationFactor);
Assert.AreEqual(mushroomsCounted, actualCount);
}
[TestMethod]
[TestCategory("09_Mushrooms_Count")]
public void Count_Mushrooms_When_All_Input_Values_Are_More_Than_Zero() {
Tuple<int, int> actualCount = new Tuple<int, int>(3, 6);
int totalMushrooms = 9;
int multilicationFactor = 2;
Tuple<int, int> mushroomsCounted = CountMushrooms(totalMushrooms, multilicationFactor);
Assert.AreEqual(mushroomsCounted, actualCount);
}
private Tuple<int, int> CountMushrooms(int totalMushrooms, int multiplicationFactor) {
bool validData = ValidateInputData(totalMushrooms, multiplicationFactor);
if (validData){
int whiteCount = totalMushrooms / (multiplicationFactor + 1);
int redCount = (totalMushrooms * multiplicationFactor) / (multiplicationFactor + 1);
return new Tuple<int, int>(whiteCount, redCount);
}
return new Tuple<int, int>(-1, -1);
}
private bool ValidateInputData(int totalMushrooms, int multiplicationFactor) {
bool totalMushroomsIsNotZeroOrNegative = totalMushrooms > 0;
bool divisionHaveNoRemainder = totalMushrooms % (multiplicationFactor + 1) == 0;
bool validMultiplicationFactor = multiplicationFactor > 0;
return totalMushroomsIsNotZeroOrNegative && divisionHaveNoRemainder && validMultiplicationFactor;
}
}
}