forked from TheAlgorithms/Go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsieve_test.go
46 lines (35 loc) · 996 Bytes
/
sieve_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// sieve_test.go
// description: Testing all the algorithms related to the generation of prime numbers in sieve.go
// author(s) [Taj](https://github.com/tjgurwara99)
// see sieve.go
package prime
import (
"reflect"
"testing"
)
func TestSieve(t *testing.T) {
firstTenPrimes := [10]int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29}
t.Run("First 10 primes test", func(t *testing.T) {
var testTenPrimes [10]int
ch := make(chan int)
go GenerateChannel(ch)
for i := 0; i < 10; i++ {
testTenPrimes[i] = <-ch
ch1 := make(chan int)
go Sieve(ch, ch1, testTenPrimes[i])
ch = ch1
}
if firstTenPrimes != testTenPrimes {
t.Errorf("The first 10 primes do not match")
}
})
}
func TestGeneratePrimes(t *testing.T) {
firstTenPrimes := []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29}
t.Run("Testing GeneratePrimes Function", func(t *testing.T) {
testPrimes := Generate(10)
if !reflect.DeepEqual(firstTenPrimes, testPrimes) {
t.Fatal("GeneratePrimes function failed")
}
})
}