Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
okkhoy committed Feb 3, 2023
1 parent 09c19f5 commit 6ff2f17
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
8 changes: 8 additions & 0 deletions text-ui-test/EXPECTED.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
I'm a Duck
Quack Quack
I'm a parrot
Polly wants a cracker
Adding item value: 25
Ignoring low value item: 1
Adding item value: 33
Total value of equipments 58
21 changes: 21 additions & 0 deletions text-ui-test/runtest.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@ECHO OFF

REM create bin directory if it doesn't exist
if not exist ..\bin mkdir ..\bin

REM delete output from previous run
del ACTUAL.TXT

REM compile the code into the bin folder
javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\*.java
IF ERRORLEVEL 1 (
echo ********** BUILD FAILURE **********
exit /b 1
)
REM no error here, errorlevel == 0

REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT
java -classpath ..\bin Circus > ACTUAL.TXT

REM compare the output to the expected output
FC ACTUAL.TXT EXPECTED.TXT
34 changes: 34 additions & 0 deletions text-ui-test/runtest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

# create bin directory if it doesn't exist
if [ ! -d "../bin" ]
then
mkdir ../bin
fi

# delete output from previous run
if [ -e "./ACTUAL.TXT" ]
then
rm ACTUAL.TXT
fi

# compile the code into the bin folder, terminates if error occurred
if ! javac -cp ../src -Xlint:none -d ../bin ../src/main/java/*.java
then
echo "********** BUILD FAILURE **********"
exit 1
fi

# run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT
java -classpath ../bin Circus > ACTUAL.TXT

# compare the output to the expected output
diff ACTUAL.TXT EXPECTED.TXT
if [ $? -eq 0 ]
then
echo "Test result: PASSED"
exit 0
else
echo "Test result: FAILED"
exit 1
fi

0 comments on commit 6ff2f17

Please sign in to comment.