diff --git a/go/tests/doop_test/doop_correct/main.go b/go/tests/doop_test/doop_correct/main.go index d1c06328..b882bacb 100644 --- a/go/tests/doop_test/doop_correct/main.go +++ b/go/tests/doop_test/doop_correct/main.go @@ -10,35 +10,27 @@ func main() { if len(os.Args) == 4 { a, err := strconv.Atoi(os.Args[1]) if err != nil { - fmt.Println(0) return } b, err := strconv.Atoi(os.Args[3]) if err != nil { - fmt.Println(0) return } operator := os.Args[2] switch operator { case "+": result := a + b - if (result > a) != (b > 0) { - fmt.Println(0) - } else { + if (result > a) == (b > 0) { fmt.Println(result) } case "-": result := a - b - if (result < a) != (b > 0) { - fmt.Println(0) - } else { + if (result < a) == (b > 0) { fmt.Println(result) } case "*": result := a * b - if a != 0 && (result/a != b) { - fmt.Println(0) - } else { + if a == 0 || (result/a == b) { fmt.Println(result) } case "/": diff --git a/subjects/doop.en.md b/subjects/doop.en.md index 63476d15..a5b61964 100644 --- a/subjects/doop.en.md +++ b/subjects/doop.en.md @@ -7,16 +7,10 @@ Write a program that is called `doop`. The program has to be used with three arguments: - A value -- An operator +- An operator, one of : `+`, `-`, `/`, `*`, `%` - Another value -You should use `int64`. - -The following operators are considered valid: `+`, `-`, `/`, `*`, `%`. - -In case of an invalid operator or overflow the programs prints `0`. - -In case of an invalid number of arguments the program prints nothing. +In case of an invalid operator, value, number of arguments or an overflow the programs prints nothing. The program has to handle the modulo and division operations by 0 as shown on the output examples below. @@ -27,10 +21,8 @@ student@ubuntu:~/[[ROOT]]/test$ go build doop.go student@ubuntu:~/[[ROOT]]/test$ ./doop student@ubuntu:~/[[ROOT]]/test$ ./doop 1 + 1 | cat -e 2$ -student@ubuntu:~/[[ROOT]]/test$ ./doop hello + 1 | cat -e -0$ -student@ubuntu:~/[[ROOT]]/test$ ./doop 1 p 1 | cat -e -0$ +student@ubuntu:~/[[ROOT]]/test$ ./doop hello + 1 +student@ubuntu:~/[[ROOT]]/test$ ./doop 1 p 1 student@ubuntu:~/[[ROOT]]/test$ ./doop 1 / 0 | cat -e No division by 0$ student@ubuntu:~/[[ROOT]]/test$ ./doop 1 % 0 | cat -e