Class: TestAtcNode

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_model/atcnode.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'test/test_model/atcnode.rb', line 13

def setup
  @root = ODDB::AtcNode.new(nil)
  @atcN = ODDB::AtcClass.new('N')
  @atcN01 = ODDB::AtcClass.new('N01')
  @atcN02 = ODDB::AtcClass.new('N02')
  @atcN01A = ODDB::AtcClass.new('N01A')
  @nodeN = ODDB::AtcNode.new(@atcN)
  @nodeN01 = ODDB::AtcNode.new(@atcN01)
  @nodeN02 = ODDB::AtcNode.new(@atcN02)
  @nodeN01A = ODDB::AtcNode.new(@atcN01A)
  [@nodeN, @nodeN01, @nodeN02, @nodeN01A].each {|nd|
    @root.add_offspring(nd)
  }
end

- (Object) test_add_offspring



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'test/test_model/atcnode.rb', line 27

def test_add_offspring
  root = ODDB::AtcNode.new(nil)
  atc = ODDB::AtcClass.new('N')
  node = ODDB::AtcNode.new(atc)
  root.add_offspring(node)
  assert_equal([node], root.children)
  atc2 = ODDB::AtcClass.new('N01')
  node2 = ODDB::AtcNode.new(atc2)
  root.add_offspring(node2)
  assert_equal([node], root.children)
  assert_equal([node2], node.children)
  atc3 = ODDB::AtcClass.new('N01A')
  node3 = ODDB::AtcNode.new(atc3)
  root.add_offspring(node3)
  assert_equal([node], root.children)
  assert_equal([node2], node.children)
  assert_equal([node3], node2.children)
  atc4 = ODDB::AtcClass.new('A')
  node4 = ODDB::AtcNode.new(atc4)
  root.add_offspring(node4)
  assert_equal([node, node4], root.children)
  assert_equal([node2], node.children)
  assert_equal([node3], node2.children)
end

- (Object) test_delete



90
91
92
93
94
# File 'test/test_model/atcnode.rb', line 90

def test_delete
  assert_equal([@nodeN01, @nodeN02], @nodeN.children)
  @root.delete('N02')
  assert_equal([@nodeN01], @nodeN.children)
end

- (Object) test_each



101
102
103
104
105
# File 'test/test_model/atcnode.rb', line 101

def test_each
  collection = []
  @nodeN.each do |node| collection.push node.code end
  assert_equal ['N', 'N01', 'N02'], collection
end

- (Object) test_has_sequence



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'test/test_model/atcnode.rb', line 51

def test_has_sequence
  assert_equal(false, @root.has_sequence?)
  assert_equal(false, @nodeN.has_sequence?)
  assert_equal(false, @nodeN01.has_sequence?)
  assert_equal(false, @nodeN02.has_sequence?)
  assert_equal(false, @nodeN01A.has_sequence?)
  @atcN01.add_sequence('seq')
  assert_equal(true, @root.has_sequence?)
  assert_equal(true, @nodeN.has_sequence?)
  assert_equal(true, @nodeN01.has_sequence?)
  assert_equal(false, @nodeN02.has_sequence?)
  assert_equal(false, @nodeN01A.has_sequence?)
end

- (Object) test_level



64
65
66
67
68
69
70
71
72
73
74
75
# File 'test/test_model/atcnode.rb', line 64

def test_level
  atcN01AB = ODDB::AtcClass.new('N01AB')
  atcN01AB23 = ODDB::AtcClass.new('N01AB23')
  nodeN01AB = ODDB::AtcNode.new(atcN01AB)
  nodeN01AB23 = ODDB::AtcNode.new(atcN01AB23)
  assert_equal(0, @root.level)
  assert_equal(1, @nodeN.level)
  assert_equal(2, @nodeN01.level)
  assert_equal(3, @nodeN01A.level)
  assert_equal(4, nodeN01AB.level)
  assert_equal(5, nodeN01AB23.level)
end

- (Object) test_method



95
96
97
98
99
100
# File 'test/test_model/atcnode.rb', line 95

def test_method
  mcode = @nodeN.method(:code)
  assert_equal 'N', mcode.call
  mchildren = @nodeN.method(:children)
  assert_equal [@nodeN01, @nodeN02], mchildren.call
end

- (Object) test_path_to



76
77
78
79
80
81
82
83
84
85
# File 'test/test_model/atcnode.rb', line 76

def test_path_to
  atc = ODDB::AtcClass.new('N')
  atcnode = ODDB::AtcNode.new(atc)
  assert_equal(true, atcnode.path_to?('N01'))
  assert_equal(false, atcnode.path_to?('A01B'))
  atc = ODDB::AtcClass.new('A01B')
  atcnode = ODDB::AtcNode.new(atc)
  assert_equal(true, atcnode.path_to?('A01B'))
  assert_equal(false, atcnode.path_to?('A01'))
end

- (Object) test_root_node_path_to



86
87
88
89
# File 'test/test_model/atcnode.rb', line 86

def test_root_node_path_to
  node = ODDB::AtcNode.new(nil)
  assert_equal(true, node.path_to?('A'))  
end