Skip to content

Commit 084c31f

Browse files
committed
Added a new repository called write_test_cases which adds test cases in a go project
1 parent 2195d8c commit 084c31f

File tree

5 files changed

+118
-0
lines changed

5 files changed

+118
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module aniket-batabyal.com/mathematicalOperations
2+
3+
go 1.20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package mathematicalOperations
2+
3+
import (
4+
"errors"
5+
)
6+
7+
func Summation(numbers []rune) rune {
8+
var sum rune = 0
9+
for _, val := range numbers {
10+
sum += val
11+
}
12+
13+
return sum
14+
}
15+
16+
func Multiplication(numbers []int) (int, error) {
17+
var multipliedSoFar int = 1
18+
19+
for _, num := range numbers {
20+
21+
if num < 1 {
22+
return 0, errors.New("numbers to be multiplied should be greater than 0")
23+
}
24+
25+
multipliedSoFar *= num
26+
}
27+
28+
return multipliedSoFar, nil
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package mathematicalOperations
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestSummationNumbers(t *testing.T) {
8+
9+
var valuesToSum []rune = []rune{
10+
1,
11+
2,
12+
3,
13+
4,
14+
5,
15+
}
16+
17+
want := 15
18+
summation := Summation(valuesToSum)
19+
20+
if rune(want) != summation {
21+
t.Fatalf("The summation values was not the expected result that we wanted")
22+
}
23+
}
24+
25+
func TestMultiplicationNonZeroNumbers(t *testing.T) {
26+
var numbersToMultiply []int = []int{
27+
1,
28+
2,
29+
3,
30+
4,
31+
5,
32+
}
33+
34+
want := 120
35+
36+
multiplicationValue, error := Multiplication(numbersToMultiply)
37+
38+
if error != nil && want != multiplicationValue {
39+
t.Fatal(error)
40+
}
41+
42+
}

write_test_cases/mathematician/go.mod

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module aniket-batabyal.com/mathematician
2+
3+
go 1.20
4+
5+
replace aniket-batabyal.com/mathematicalOperations => ../mathematicalOperations
6+
7+
require aniket-batabyal.com/mathematicalOperations v0.0.0-00010101000000-000000000000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"aniket-batabyal.com/mathematicalOperations"
8+
)
9+
10+
func main() {
11+
12+
var numbersToSum []rune = []rune{
13+
1,
14+
2,
15+
3,
16+
4,
17+
5,
18+
}
19+
20+
var numbersToMultiply []int = []int{
21+
10,
22+
20,
23+
30,
24+
40,
25+
1,
26+
10,
27+
}
28+
29+
multipliedValues, error := mathematicalOperations.Multiplication(numbersToMultiply)
30+
31+
if error != nil {
32+
log.Fatal(error)
33+
}
34+
35+
fmt.Println("The summation result: ", mathematicalOperations.Summation(numbersToSum))
36+
fmt.Println("The multiplication result: ", multipliedValues)
37+
}

0 commit comments

Comments
 (0)