File tree 2 files changed +45
-0
lines changed
2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ add () {
3
+ IFS=" ," read -ra numbers <<< " $1"
4
+ local sum=0
5
+ lista=( " pippo" " pluto" " pape rino" )
6
+ for number in " ${numbers[@]} "
7
+ do
8
+ (( sum+= number))
9
+ done
10
+ echo " $sum "
11
+ return
12
+ }
13
+ [[ $BASH_SOURCE == $0 ]] && add " $@ "
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ stampa_risultato_dei_test () {
3
+ if [[ $? == 0 ]]
4
+ then
5
+ tput setaf 2; echo " ALL PASSED" ; tput sgr0
6
+ else
7
+ tput setaf 1; echo " SOME PROBLEMS" ; tput sgr0
8
+ fi
9
+ }
10
+ assert_equal () {
11
+ echo " $1 " > actual.txt
12
+ echo " $2 " > expected.txt
13
+ diff -u expected.txt actual.txt
14
+ }
15
+
16
+ source bin/add
17
+
18
+ assert_equal " 0" " $( add " " ) "
19
+
20
+ assert_equal " 1" " $( add 1) "
21
+ assert_equal " 2" " $( add 2) "
22
+
23
+ assert_equal " 3" " $( add 1,2) "
24
+ assert_equal " 5" " $( add 2,3) "
25
+
26
+ assert_equal " 8" " $( add 2,3,3) "
27
+ assert_equal " 10" " $( add 2,2,3,3) "
28
+
29
+ assert_equal " 10" " $( bin/add 1,2,3,4) "
30
+ assert_equal " " " $( source bin/add) "
31
+
32
+ stampa_risultato_dei_test
You can’t perform that action at this time.
0 commit comments