Class: TestKyaniteOptimizer

Inherits
UnitTest
  • Object
show all
Defined in
test/test_optimizer.rb

Optimizer

Kyanite definitions

Optimizer

Kyanite tests and examples

TestKyaniteOptimizer

Find objects with min or max score. Each object is written to the Optimizer by a push command, together with it's score. content_max and content_min result the object with the highest / lowest score. The access to the second and third objects is possible by deleting objects with delete_max or delete_min.

Instance Method Summary (collapse)

Instance Method Details

- (Object) pppest_cleanup



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'test/test_optimizer.rb', line 84

def pppest_cleanup
  test = Optimizer.new
  assert_equal false,                         test.cleanup!    
  assert_equal 0,                             test.size  
  test.push  1,  'hallo'
  assert_equal false,                         test.cleanup!
  assert_equal 1,                             test.size      
  test.push  5,  'eintrag'
  assert_equal false,                         test.cleanup! 
  assert_equal 2,                             test.size  
  test.push  6,  'maximum'
  assert_equal true,                          test.cleanup! 
  assert_equal 2,                             test.size  
  test.push -1,  'minimum'
  assert_equal true,                          test.cleanup! 
  assert_equal 2,                             test.size      
  test.push -1,  'noch ein minimum'
  assert_equal false,                         test.cleanup!      
  assert_equal 2,                             test.size      
  test.push  0,  'blubb'
  assert_equal true,                          test.cleanup!
  assert_equal 2,                             test.size      
  test.push  6,  'noch ein maximum'
  assert_equal false,                         test.cleanup! 
  assert_equal 2,                             test.size      
  
  assert_equal 'minimum',                     test.content_min[0]
  assert_equal  -1,                           test.score_min
  assert_equal 'maximum',                     test.content_max[0]
  assert_equal  6,                            test.score_max       
end

- (Object) test_basics



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
# File 'test/test_optimizer.rb', line 15

def test_basics
  test = Optimizer.new
  test.push  1,  'hallo'
  test.push  5,  'eintrag'
  test.push  6,  'maximum'
  test.push -1,  'minimum'
  test.push -1,  'noch ein minimum'  
  test.push  6,  'noch ein maximum'    
  test.push  0,   'blubb'
  assert_equal 'minimum',                     test.content_min
  assert_equal  -1,                           test.score_min
  assert_equal 'maximum',                     test.content_max
  assert_equal  6,                            test.score_max   
  
  assert_equal true,                          test.delete_min
  assert_equal 'blubb',                       test.content_min
  assert_equal  0,                            test.score_min 
  assert_equal 'maximum',                     test.content_max
  assert_equal  6,                            test.score_max   
  
  assert_equal true,                          test.delete_max
  assert_equal 'eintrag',                     test.content_max
  assert_equal  5,                            test.score_max
  assert_equal 'blubb',                       test.content_min
  assert_equal  0,                            test.score_min 
  test.push  6,  'maximum'
  assert_equal 'maximum',                     test.content_max
  assert_equal  6,                            test.score_max       
end

- (Object) test_leer



75
76
77
78
79
80
81
# File 'test/test_optimizer.rb', line 75

def test_leer
  test = Optimizer.new
  assert_equal nil,                           test.content_min
  assert_equal nil,                           test.score_min 
  assert_equal nil,                           test.content_max
  assert_equal nil,                           test.score_max   
end

- (Object) test_range



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
# File 'test/test_optimizer.rb', line 47

def test_range
  test = Optimizer.new
  test.push 1,   'hallo'
  test.push 5,   'eintrag'
  test.push 6,   'maximum'
  test.push -1,  'minimum'
  test.push -1,  'noch ein minimum'  
  test.push  6,  'noch ein maximum'    
  test.push 0,   'blubb'
  assert_equal 'minimum',                     test.content_min(0..0)
  assert_equal 'minimum',                     test.content_min(0)
  assert_equal 'noch ein minimum',            test.content_min(1..1)
  assert_equal 'noch ein minimum',            test.content_min(1)
  assert_equal ['minimum', 
                'noch ein minimum'],          test.content_min(0..-1)
  assert_equal  -1,                           test.score_min
  assert_equal 'maximum',                     test.content_max(0..0)
  assert_equal 'maximum',                     test.content_max(0)
  assert_equal 'noch ein maximum',            test.content_max(1..1)
  assert_equal 'noch ein maximum',            test.content_max(1)
  assert_equal ['maximum', 
                'noch ein maximum'],          test.content_max(0..1)
  # assert_equal ['noch ein maximum',                   
                # 'maximum'],                   test.content_max(1..0)
  assert_equal  6,                            test.score_max   
end