-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSevenOutTesting.cs
More file actions
155 lines (142 loc) · 6.47 KB
/
SevenOutTesting.cs
File metadata and controls
155 lines (142 loc) · 6.47 KB
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DieGame2
{
internal class SevenOutTesting : ITesting
{
/// <summary>
/// A reference to the SevenOut object
/// </summary>
private SevenOut _sevenOutGame;
/// <summary>
/// A reference to the LogFile object
/// </summary>
private LogFile _logFile;
/// <summary>
/// A property to access the reference to SevenOut object
/// </summary>
public SevenOut GetGame
{
get { return _sevenOutGame; }
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="game"> A reference to a SevenOut object</param>
public SevenOutTesting(SevenOut game)
{
_sevenOutGame = game;
_logFile = new LogFile("sevenOutLogFile.txt");
}
/// <summary>
/// Implementation for the CheckDieRange method defined by the interface
/// </summary>
void ITesting.CheckDieRange()
{
Debug.Assert(_sevenOutGame.GetDie1.CurrentValue >= 1 && _sevenOutGame.GetDie1.CurrentValue <= 6, "Die value must be from 1 to 6, inclusive.");
Debug.Assert(_sevenOutGame.GetDie1.CurrentValue >= 1 && _sevenOutGame.GetDie2.CurrentValue <= 6, "Die value must be from 1 to 6, inclusive.");
if ((_sevenOutGame.GetDie1.CurrentValue >= 1 && _sevenOutGame.GetDie1.CurrentValue <= 6)
&& (_sevenOutGame.GetDie1.CurrentValue >= 1 && _sevenOutGame.GetDie2.CurrentValue <= 6))
{
_logFile.Log($"{DateTime.Now}. Test passed: 2 dice value are from 1 to 6 (inclusive). ({_sevenOutGame.GetDie1.CurrentValue}, {_sevenOutGame.GetDie2.CurrentValue})");
}
else
{
_logFile.Log($"{DateTime.Now}. Test failed: Dice value are out of range 1 to 6. ({_sevenOutGame.GetDie1.CurrentValue}, {_sevenOutGame.GetDie2.CurrentValue})");
}
}
/// <summary>
/// Implementation for the CheckGameCondition method defined by the interface
/// </summary>
void ITesting.CheckGameCondition()
{
Debug.Assert(
(_sevenOutGame.GetTempTotal == 7 && _sevenOutGame.GetStatus == true)
|| (_sevenOutGame.GetTempTotal != 7 && _sevenOutGame.GetStatus == false),
"The game ends when total = 7");
if ((_sevenOutGame.GetTempTotal == 7 && _sevenOutGame.GetStatus == true)
|| (_sevenOutGame.GetTempTotal != 7 && _sevenOutGame.GetStatus == false))
{
_logFile.Log("Test passed: The game ends when the total is 7.");
}
else
{
_logFile.Log("Test failed: The game does not end when the total is 7.");
_logFile.Log($"{_sevenOutGame.GetTempTotal} & {_sevenOutGame.GetStatus}.");
}
}
/// <summary>
/// Implementation for the CheckPointsCalculation method defined by the interface
/// </summary>
void ITesting.CheckPointsCalculation()
{
if (_sevenOutGame.GetDie1.CurrentValue == _sevenOutGame.GetDie2.CurrentValue)
{
Debug.Assert(_sevenOutGame.GetPointsList[_sevenOutGame.GetCurrentTurn -1]
== _sevenOutGame.GetCurrentPoint + 2*(_sevenOutGame.GetTempTotal), "The point was calculated incorrectly.");
}
else
{
Debug.Assert(_sevenOutGame.GetPointsList[_sevenOutGame.GetCurrentTurn - 1]
== _sevenOutGame.GetCurrentPoint + _sevenOutGame.GetTempTotal, "The point was calculated incorrectly.");
}
if (_sevenOutGame.GetDie1.CurrentValue == _sevenOutGame.GetDie2.CurrentValue)
{
if (_sevenOutGame.GetPointsList[_sevenOutGame.GetCurrentTurn - 1]
== _sevenOutGame.GetCurrentPoint + 2 * (_sevenOutGame.GetTempTotal))
{
_logFile.Log("Test passed: The point was calculated correctly.");
_logFile.Log($"Previous point: {_sevenOutGame.GetCurrentPoint} / Dice value total: {_sevenOutGame.GetTempTotal} " +
$"/ Calculated Points: {_sevenOutGame.GetPointsList[_sevenOutGame.GetCurrentTurn - 1]}.");
}
else
{
_logFile.Log("Test passed: The point was calculated incorrectly.");
_logFile.Log($"Previous point: {_sevenOutGame.GetCurrentPoint} / Dice value total: {_sevenOutGame.GetTempTotal} " +
$"/ Calculated Points: {_sevenOutGame.GetPointsList[_sevenOutGame.GetCurrentTurn - 1]}.");
}
}
else
{
if (_sevenOutGame.GetPointsList[_sevenOutGame.GetCurrentTurn - 1]
== _sevenOutGame.GetCurrentPoint + _sevenOutGame.GetTempTotal)
{
_logFile.Log("Test passed: The point was calculated correctly.");
_logFile.Log($"Previous point: {_sevenOutGame.GetCurrentPoint} / Dice value total: {_sevenOutGame.GetTempTotal} " +
$"/ Calculated Points: {_sevenOutGame.GetPointsList[_sevenOutGame.GetCurrentTurn - 1]}.");
}
else
{
_logFile.Log("Test passed: The point was calculated incorrectly.");
_logFile.Log($"Previous point: {_sevenOutGame.GetCurrentPoint} / Dice value total: {_sevenOutGame.GetTempTotal} " +
$"/ Calculated Points: {_sevenOutGame.GetPointsList[_sevenOutGame.GetCurrentTurn - 1]}.");
}
}
}
/// <summary>
/// A public method to invoke the CheckDieRange method
/// </summary>
public void GetCheckDieRange()
{
((ITesting)this).CheckDieRange();
}
/// <summary>
/// A public method to invoke the CheckGameCondition method
/// </summary>
public void GetCheckGameCondition()
{
((ITesting)this).CheckGameCondition();
}
/// <summary>
/// A public method to invoke the CheckPointsCalculation method
/// </summary>
public void GetCheckPointsCalculation()
{
((ITesting)this).CheckPointsCalculation();
}
}
}