cooper-union-ece-160/1-bday/tests/test.sh

56 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Copyright (C) 2020 Gary Kim <gary@garykim.dev>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
set -euf -o pipefail
# This line will only work in scripts and not sourced bash scripts.
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
TESTING=${TESTING:-"$SCRIPTPATH/../bdaycardgen.sh"}
SHUNIT2=${SHUNIT2:-"$SCRIPTPATH/../../3rdparty/shunit2/shunit2"}
testNormalYears() {
VALUES=("1st" "2nd" "3rd" "4th" "11th" "12th" "13th" "21st" "22nd" "23rd" "30th" "31st")
for i in ${VALUES[*]}; do
assertContains "Check for $i" "$("$TESTING" "Generic Name" ${i::-2} "Generic Sender")" "$i"
done
}
testExtremelyLargeYears() {
VALUES=("101st" "102nd" "103rd" "104th" "111th" "112th" "113th" "121st" "122nd" "123rd" "130th" "131st")
for i in ${VALUES[*]}; do
assertContains "Check for $i" "$("$TESTING" "Generic Name" ${i::-2} "Generic Sender")" "$i"
done
}
testNumberOfHappy() {
assertContains "1 Happy" "$("$TESTING" "Generic Name" 1 "Generic Sender")" "Happy 1"
assertContains "3 Happy(s)" "$("$TESTING" "Generic Name" 3 "Generic Sender")" "Happy Happy Happy 3"
assertContains "5 Happy(s)" "$("$TESTING" "Generic Name" 5 "Generic Sender")" "Happy Happy Happy Happy Happy 5"
}
testSanityCheck() {
assertEquals "Incorrect number of arguments" "$("$TESTING" "Generic Name" 1 "Generic Sender" "hahaha")"
}
testHelpInfo() {
assertContains "Usage info from --help" "$("$TESTING" --help)" "Usage: "
assertContains "Usage info from -h" "$("$TESTING" -h)" "Usage: "
}
. "$SHUNIT2"