Skip to content

Commit 750ac59

Browse files
Merge pull request #4 from rforzachamp821/Ryan_WorkingBranch
From: Ryan working branch What it is implementing: v0.9.0 update
2 parents ee1217f + 38d3fdd commit 750ac59

36 files changed

+2146
-602
lines changed

CommandFiles/CPUStress.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ void CpuStressTestWorker() {
1717
long double ldStress = 1.0;
1818

1919
while (!StopCpuStress) {
20-
ldStress *= RandNum(0, 5);
21-
ldStress /= RandNum(0.00000001, 5);
22-
ldStress += RandNum(0, 5);
20+
ldStress *= RandNumld(0, 5);
21+
ldStress /= RandNumld(0.00000001, 5);
22+
ldStress += RandNumld(0, 5);
2323
}
2424

2525
return;
@@ -30,9 +30,9 @@ void CpuBenchmarkWorker() {
3030
long double ldStress = 1.0;
3131

3232
while (!StopCpuStress) {
33-
ldStress *= RandNum(0, 5);
34-
ldStress /= RandNum(0.00000001, 5);
35-
ldStress += RandNum(0, 5);
33+
ldStress *= RandNumld(0, 5);
34+
ldStress /= RandNumld(0.00000001, 5);
35+
ldStress += RandNumld(0, 5);
3636
nCurrentReiterationNum++;
3737
}
3838
return;
@@ -96,12 +96,15 @@ void CpuBenchmark(short int nSingleOrMulti, long long int nArgNum = -1) {
9696
std::thread SingleCoreWorker(CpuBenchmarkWorker);
9797

9898
while (true) {
99-
99+
// Terminate on ESC keypress
100100
if (_kbhit()) {
101-
bCpuStressKeyboardTermination = true;
102-
break;
101+
if (_getch_nolock() == 27) {
102+
bCpuStressKeyboardTermination = true;
103+
break;
104+
}
105+
ClearKeyboardBuffer();
103106
}
104-
else if (nCurrentReiterationNum >= nReiterationCount) {
107+
if (nCurrentReiterationNum >= nReiterationCount) {
105108
break;
106109
}
107110

@@ -128,7 +131,7 @@ void CpuBenchmark(short int nSingleOrMulti, long long int nArgNum = -1) {
128131
else {
129132
colour(YLW, ConfigObjMain.sColourGlobalBack);
130133
ClearKeyboardBuffer();
131-
std::cout << wordWrap("\n\nThe single-core benchmark was terminated by a keyboard press.");
134+
std::cout << wordWrap("\n\nThe single-core benchmark was terminated by an ESC keyboard press.");
132135
Exiting();
133136
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
134137
}
@@ -155,11 +158,15 @@ void CpuBenchmark(short int nSingleOrMulti, long long int nArgNum = -1) {
155158

156159
while (true) {
157160

161+
// Terminate on ESC keypress
158162
if (_kbhit()) {
159-
bCpuStressKeyboardTermination = true;
160-
break;
163+
if (_getch_nolock() == 27) {
164+
bCpuStressKeyboardTermination = true;
165+
break;
166+
}
167+
ClearKeyboardBuffer();
161168
}
162-
else if (nCurrentReiterationNum >= nReiterationCount) {
169+
if (nCurrentReiterationNum >= nReiterationCount) {
163170
break;
164171
}
165172

@@ -187,7 +194,7 @@ void CpuBenchmark(short int nSingleOrMulti, long long int nArgNum = -1) {
187194
}
188195
else {
189196
colour(YLW, ConfigObjMain.sColourGlobalBack);
190-
std::cout << wordWrap("\n\nThe single-core benchmark was terminated by a keyboard press.");
197+
std::cout << wordWrap("\n\nThe multi-core benchmark was terminated by an ESC keyboard press.");
191198
Exiting();
192199
ClearKeyboardBuffer();
193200
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
@@ -226,7 +233,7 @@ void CpuStressTest(short int nSingleOrMulti, bool bIsArgument = false) {
226233
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
227234
}
228235

229-
std::cout << wordWrap("Remember, you can always stop the stress test by pressing any key while it's going.\nPress any key to begin the test, or ESC to terminate...");
236+
std::cout << wordWrap("Remember, you can always stop the stress test by pressing the ESC key while it's going.\nPress any key to begin the test, or ESC to terminate...");
230237
char cKeyCST = _getch();
231238
if (cKeyCST == 27) {
232239
colour(YLW, ConfigObjMain.sColourGlobalBack);
@@ -245,7 +252,7 @@ void CpuStressTest(short int nSingleOrMulti, bool bIsArgument = false) {
245252
std::thread SingleCoreStressTest(CpuStressTestWorker);
246253

247254
// Then wait for keyboard hit to kill all the processes
248-
while (!_kbhit()) {
255+
while (!_kbhit() || _getch() != 27) {
249256
sleep(10);
250257
}
251258

@@ -277,7 +284,7 @@ void CpuStressTest(short int nSingleOrMulti, bool bIsArgument = false) {
277284
vThreads[i] = std::thread(CpuStressTestWorker);
278285
}
279286
// Then wait for keyboard hit to kill all the processes
280-
while (!_kbhit()) {
287+
while (!_kbhit() || _getch() != 27) {
281288
sleep(10);
282289
}
283290

CommandFiles/CalculationAlgorithm/CalculationAlgorithm.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,33 @@ class CalculationAlgorithm
5050

5151

5252
// VerifyIfStringIsNumerical - Checks whether std::string argument is a true number or not
53-
// Arguments: sNumberTest - The number string to check.
53+
// Parameters: sNumberTest - The number string to check.
5454
// Return Values: TRUE or 1 for number, FALSE or 0 for not a number.
5555
//
5656
bool VerifyIfStringIsNumerical(const std::string sNumberTest);
5757

5858
// FormatValueForDisplay - Formats a specific value for display output.
5959
// - Has a max of 15-16dp.
60-
// Arguments: dValue - The number to format.
60+
// Parameters: dValue - The number to format.
6161
// Return Value: Formatted number as a string.
6262
//
6363
std::string FormatValueForDisplay(long double dValue);
6464

6565
// FormatValueForAlgorithm - Formats a specific value for internal algorithm calculations.
6666
// - Has a max of 18-19dp.
67-
// Arguments: dValue - The number to format.
67+
// Parameters: dValue - The number to format.
6868
// Return Value: Formatted number as a string.
6969
//
7070
std::string FormatValueForAlgorithm(long double dValue);
7171

7272
// FormatStringForDisplay - Formats a calculation string for display output, by rounding the numbers inside and removing the zeroes from them.
73-
// Arguments: sCalculationString - The string to format.
73+
// Parameters: sCalculationString - The string to format.
7474
// Return value: Formatted string.
7575
//
7676
std::string FormatStringForDisplay(std::string sCalculationString);
7777

7878
// FormatStringForAlgorithm - Formats a calculation string for algorithm use, including changing number formatting to the American notation.
79-
// Arguments: sCalculationString - The string to format.
79+
// Parameters: sCalculationString - The string to format.
8080
// Return value: Formatted string.
8181
//
8282
std::string FormatStringForAlgorithm(std::string sCalculationString);
@@ -103,28 +103,28 @@ class CalculationAlgorithm
103103
// Calculate - Main calculation algorithm that calculates using each of the 4 basic mathematical operators,
104104
// with negative number support along with that. The nErrorLevel variable is modified when
105105
// anything goes wrong.
106-
// Arguments: sCalculationString - The calculation string to work out the product of/find the answer of.
106+
// Parameters: sCalculationString - The calculation string to work out the product of/find the answer of.
107107
// Return values: The calculated answer in long double-grade precision.
108108
//
109109
long double Calculate(std::string sCalculationString);
110110

111111
// EradicateBrackets - Removes brackets from calculation string and converts them to constant numbers.
112112
// It has support for numbers before and after the brackets that are attached to the brackets.
113-
// Arguments: sCalculationString - The calculation string to remove and simplify the brackets from.
113+
// Parameters: sCalculationString - The calculation string to remove and simplify the brackets from.
114114
// Return values: Modified string
115115
//
116116
std::string EradicateBrackets(std::string sCalculationString);
117117

118118
// RemoveUnnecessaryArithmeticSymbols - Simplifies/removes arithmetic operators that are placed next to each other,
119119
// e.g) 5+-++--+-5 simplifies to 5+5
120-
// Arguments: sCalculationString - The calculation string to remove the arithmetic symbols from.
120+
// Parameters: sCalculationString - The calculation string to remove the arithmetic symbols from.
121121
// Return values: Modified string
122122
//
123123
std::string RemoveUnnecessaryArithmeticSymbols(std::string sCalculationString);
124124

125125
// RemoveAllFormatting - Remove spaces/thousands separators from mathematical expression.
126126
// - Required in case user uses spaces/thousands separators, as spaces/thousands separators will cause unintended syntax errors.
127-
// Arguments: sCalculationString - The calculation string to remove space/thousands separator characters from.
127+
// Parameters: sCalculationString - The calculation string to remove space/thousands separator characters from.
128128
// Return values: Modified string
129129
//
130130
std::string RemoveAllFormatting(std::string sCalculationString);
@@ -141,7 +141,7 @@ class CalculationAlgorithm
141141
~CalculationAlgorithm();
142142

143143
// GetLastCalculationErrorInfo - Gets the last calculation error and outputs details as a string.
144-
// Arguments: None
144+
// Parameters: None
145145
// Return values: Error information string.
146146
//
147147
std::string GetLastCalculationErrorInfo();
@@ -151,7 +151,7 @@ class CalculationAlgorithm
151151
// 1) A math error has occured (e.g division by 0).
152152
// 2) A syntax error has occured.
153153
// 3) An unknown number parsing error has occured.
154-
// Arguments: None
154+
// Parameters: None
155155
// Return values: Last calculation error value.
156156
//
157157
inline short int GetLastCalculationErrorValue()
@@ -162,7 +162,7 @@ class CalculationAlgorithm
162162
// SafeCalculate - Calculates and finds the product of a calculation string provided by the user,
163163
// which utilises all features contained in the calculation algorithm to prepare
164164
// the calculation string for the calculation.
165-
// Arguments: sCalculationString - The string to find the product of/calculate.
165+
// Parameters: sCalculationString - The string to find the product of/calculate.
166166
// Return values: The calculated answer in long double-grade precision.
167167
//
168168
// NOTE: This function returns 0.0 if any errors occur, and sets the error level accordingly.

0 commit comments

Comments
 (0)