File tree Expand file tree Collapse file tree 9 files changed +107
-0
lines changed
Expand file tree Collapse file tree 9 files changed +107
-0
lines changed Original file line number Diff line number Diff line change 1+ DEFAULT_PATH = tests
Original file line number Diff line number Diff line change 1+ lib /
Original file line number Diff line number Diff line change 1+ # bashunit
2+
3+ 1 . Install the library: ` ./install.sh `
4+ 2 . Run the test script: ` ./test.sh `
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # ###################################################
4+ # More details about bashunit installation #
5+ # see: https://bashunit.typeddevs.com/installation #
6+ # ###################################################
7+ curl -s https://bashunit.typeddevs.com/install.sh | bash -s lib 0.11.0
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ mode=$1
4+ path=$2
5+
6+ if [ -z $path ]; then
7+ echo " Usage: ./file-report.sh [size|number-of-files] [path]" ; >&2
8+ exit 1
9+ fi
10+
11+ cd " ${path} "
12+
13+ case " ${mode} " in
14+ number-of-files)
15+ ls -1 | wc -l ;;
16+ size)
17+ du -h | cut -f1 ;;
18+ * )
19+ >&2 echo " Usage: ./file-report.sh [size|number-of-files] [path]" ; exit 1 ;;
20+ esac
21+
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ function main() {
4+ numberOfPortions=$1
5+ pricePerPortion=$( calculatePrice $numberOfPortions )
6+ totalPrice=$(( numberOfPortions * pricePerPortion ))
7+
8+ echo " Total $totalPrice "
9+ }
10+
11+ function calculatePrice() {
12+ if [[ $numberOfPortions -lt 3 ]]; then
13+ echo " 100"
14+ else
15+ day=$( getDay)
16+ if (( day % 2 )) ; then
17+ echo " 80"
18+ else
19+ echo " 100"
20+ fi
21+ fi
22+ }
23+
24+ function getDay() {
25+ date -d ' +%d'
26+ }
27+
28+ if [[ " ${BASH_SOURCE[0]} " == " ${0} " ]]; then
29+ main " $@ "
30+ fi
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ function myfun() {
4+ echo " Hello!"
5+ }
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ lib/bashunit tests
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # set_up is called before executing each test function
4+ function set_up() {
5+ source " $( realpath " ." ) /src/ice_cream_price.sh"
6+ }
7+
8+ function test_ice_cream_price_should_be_100_per_portion_for_low_quantities() {
9+ result=$( main 1)
10+
11+ assert_successful_code
12+ assert_equals " ${result} " " Total 100"
13+ }
14+
15+ function test_there_should_be_20_percent_discount_for_large_quantities_on_odd_days() {
16+ function getDay() {
17+ echo " 1"
18+ }
19+
20+ result=$( main 4)
21+
22+ assert_successful_code
23+ assert_equals " ${result} " " Total 320"
24+ }
25+
26+ function test_there_should_be_no_discount_even_for_large_quantities_on_even_days() {
27+ function getDay() {
28+ echo " 2"
29+ }
30+
31+ result=$( main 4)
32+
33+ assert_successful_code
34+ assert_equals " ${result} " " Total 400"
35+ }
You can’t perform that action at this time.
0 commit comments