-
Notifications
You must be signed in to change notification settings - Fork 24
/
GaussianConvolutionTest.groovy
76 lines (60 loc) · 1.86 KB
/
GaussianConvolutionTest.groovy
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package operators;
import spock.lang.Specification;
class GaussianConvolutionTest extends Specification {
class MockProblem {
def variance() { return 0.5 }
def min() { return 0 }
def max() { return 1 }
}
def "mutate returns a vector of the correct length in right range and doesn't change original vector"() {
given:
def problem = new MockProblem()
GaussianConvolution gc = new GaussianConvolution(variance : 0.5)
def vector = [0.96, 0.83, 0.94, 0.05, 0.78, 0.78, 0.04, 0.53, 0.32, 0.97]
def origVector = vector.clone()
when:
def w = gc.mutate(problem, vector)
then:
w.size() == vector.size()
w.every { x -> problem.min() <= x && x <= problem.max() }
(0..<vector.size()).every { i ->
vector[i] == origVector[i]
w[i] != vector[i]
}
}
def "mutate with p=0 doesn't change vector"() {
given:
def problem = new MockProblem()
GaussianConvolution gc = new GaussianConvolution(p : 0, variance : 0.5)
def vector = [0.96, 0.83, 0.94, 0.05, 0.78, 0.78, 0.04, 0.53, 0.32, 0.97]
when:
def w = gc.mutate(problem, vector)
then:
w.size() == vector.size()
(0..<vector.size()).every { i ->
w[i] == vector[i]
}
}
def "toString() builds a result with default p"() {
given:
GaussianConvolution gc = new GaussianConvolution(variance : 0.5)
when:
String s = gc.toString()
then:
// This is a quite lame test, but I don't want to create a really
// rigid test that will break just because someone wants to modify
// the toString output.
s.length() > 0
}
def "toString() builds a result"() {
given:
GaussianConvolution gc = new GaussianConvolution(p : 0.75, variance : 0.5)
when:
String s = gc.toString()
then:
// This is a quite lame test, but I don't want to create a really
// rigid test that will break just because someone wants to modify
// the toString output.
s.length() > 0
}
}