Skip to content

Commit

Permalink
Add more tests, fix major crash
Browse files Browse the repository at this point in the history
  • Loading branch information
lefticus committed Nov 17, 2023
1 parent d5575c9 commit a1b0996
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
*.{vcxproj,vcxproj.filters} text eol=crlf
/legacy/*.{cpp,hpp,h,dsp,dsw} text eol=crlf
/legacy/*.{cpp,hpp,h,dsp,dsw,plg} text eol=crlf

###############################
# Git Large File System (LFS) #
Expand Down
4 changes: 2 additions & 2 deletions legacy/StringTokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

StringTokenizer::StringTokenizer(char * n_string) {

string = new char[strlen(n_string)];
string = new char[strlen(n_string) + 1];
strcpy(string, n_string);

stringLen = strlen(string);
Expand All @@ -16,7 +16,7 @@ StringTokenizer::StringTokenizer(char * n_string) {

StringTokenizer::~StringTokenizer()
{
delete string;
delete [] string;
}

char * StringTokenizer::nextToken()
Expand Down
Binary file modified legacy/infiz.ncb
Binary file not shown.
Binary file modified legacy/infiz.opt
Binary file not shown.
34 changes: 30 additions & 4 deletions legacy/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,39 @@ void run_test(const char *input, RationalNumber expected)
// then fix later!
StringTokenizer st(const_cast<char *>(input));

RationalNumber result = *evaluateExpression(&st);
assert(result.getDenominator() == expected.getDenominator());
assert(result.getNumerator() == expected.getNumerator());
std::cout << "PASS: input: " << input << " output: " << result.getNumerator() << '/' << result.getDenominator() << '\n';
// these will have to change once I make the code correct without heap everywhere

// why you used the heap:
// * stack was too small! (not right!)
// * that's just how we did it back then! (but that's still bad practice even then!)
//
// actual reasons:
// * I didn't understand copy constructors
// * I didn't use stdlib
// * I was learning Java also at that time
// * I don't recall professors ever discussing memory leaks or efficiency!

RationalNumber *result = evaluateExpression(&st);
if (result->getDenominator() != expected.getDenominator() ||
result->getNumerator() != expected.getNumerator()) {
std::cout << "FAIL: ";
} else {
std::cout << "PASS: ";
}

std::cout << "input: " << input
<< " expected: " << expected.getNumerator() << '/' << expected.getDenominator()
<< " got: " << result->getNumerator() << '/' << result->getDenominator() << '\n';
}

int main() {
run_test("(3 + 2)", RationalNumber(5, 1));
run_test("(3 / 2)", RationalNumber(3, 2));
run_test("(4 / 2)", RationalNumber(4, 2));
run_test("(4 / 2) * 5", RationalNumber(20, 2));

// we need to evaluate this for later, I don't think
// this is correct, but we're capturing the current state of things.
run_test("1 / 2 / 3", RationalNumber(3, 2));
return 0;
}
33 changes: 27 additions & 6 deletions legacy/tests/tests.plg
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,43 @@
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: InfixEvaluator - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
Creating temporary file "C:\Users\Jason\AppData\Local\Temp\RSP31DC.tmp" with contents
[
/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fp"Debug/InfixEvaluator.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
"C:\Users\Jason\Documents\GitHub\infiz\legacy\Evaluator.cpp"
"C:\Users\Jason\Documents\GitHub\infiz\legacy\RationalNumber.cpp"
"C:\Users\Jason\Documents\GitHub\infiz\legacy\Stack.cpp"
"C:\Users\Jason\Documents\GitHub\infiz\legacy\StringTokenizer.cpp"
]
Creating command line "cl.exe @C:\Users\Jason\AppData\Local\Temp\RSP31DC.tmp"
Creating command line "link.exe -lib /nologo /out:"Debug\InfixEvaluator.lib" .\Debug\Evaluator.obj .\Debug\RationalNumber.obj .\Debug\Stack.obj .\Debug\StringTokenizer.obj "
<h3>Output Window</h3>
Compiling...
Evaluator.cpp
RationalNumber.cpp
Stack.cpp
StringTokenizer.cpp
Creating library...
<h3>
--------------------Configuration: tests - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
Creating temporary file "C:\Users\Jason\AppData\Local\Temp\RSPE6C6.tmp" with contents
Creating temporary file "C:\Users\Jason\AppData\Local\Temp\RSP3306.tmp" with contents
[
/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Debug/tests.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Debug/tests.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
"C:\Users\Jason\Documents\GitHub\infiz\legacy\tests.cpp"
]
Creating command line "cl.exe @C:\Users\Jason\AppData\Local\Temp\RSPE6C6.tmp"
Creating temporary file "C:\Users\Jason\AppData\Local\Temp\RSPE6C7.tmp" with contents
Creating command line "cl.exe @C:\Users\Jason\AppData\Local\Temp\RSP3306.tmp"
Creating temporary file "C:\Users\Jason\AppData\Local\Temp\RSP3307.tmp" with contents
[
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/tests.pdb" /debug /machine:I386 /out:"Debug/tests.exe" /pdbtype:sept
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/tests.pdb" /debug /machine:I386 /out:"Debug/tests.exe" /pdbtype:sept
.\Debug\tests.obj
\Users\Jason\Documents\GitHub\infiz\legacy\InfixEvaluator\Debug\InfixEvaluator.lib
]
Creating command line "link.exe @C:\Users\Jason\AppData\Local\Temp\RSPE6C7.tmp"
Creating command line "link.exe @C:\Users\Jason\AppData\Local\Temp\RSP3307.tmp"
<h3>Output Window</h3>
Compiling...
tests.cpp
Expand Down

0 comments on commit a1b0996

Please sign in to comment.