rufus-decision 1.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,27 +2,18 @@
2
2
  #
3
3
  # Testing rufus-deciision
4
4
  #
5
- # John Mettraux at openwfe.org
6
- #
7
5
  # Sun Oct 29 15:41:44 JST 2006
8
6
  #
9
7
 
10
8
  require 'test/unit'
11
9
 
12
- require 'dmixin'
10
+ require File.dirname(__FILE__) + '/test_base.rb'
13
11
 
14
12
 
15
- class DecisionTest < Test::Unit::TestCase
13
+ class Decision1Test < Test::Unit::TestCase
16
14
  include DecisionTestMixin
17
15
 
18
- #def setup
19
- #end
20
-
21
- #def teardown
22
- #end
23
-
24
- CSV1 = \
25
- """
16
+ CSV1 = %{
26
17
  ,,
27
18
  in:fx,in:fy,out:fz
28
19
  ,,
@@ -30,39 +21,76 @@ a,${fx},0
30
21
  c,d,${fx}
31
22
  e,f,${r:3+4}
32
23
  g,h,${r:'${fx}' + '${fy}'}
33
- """
24
+ }
34
25
 
35
26
  def test_1
36
27
 
37
- wi = {
38
- "fx" => "c",
39
- "fy" => "d"
40
- }
41
- do_test(CSV1, wi, {}, { "fz" => "c" }, false)
28
+ wi = { 'fx' => 'c', 'fy' => 'd' }
29
+ do_test(CSV1, wi, {}, { 'fz' => 'c' }, false)
42
30
 
43
- wi = {
44
- "fx" => "a",
45
- "fy" => "a"
46
- }
47
- do_test(CSV1, wi, {}, { "fz" => "0" }, false)
31
+ wi = { 'fx' => 'a', 'fy' => 'a' }
32
+ do_test(CSV1, wi, {}, { 'fz' => '0' }, false)
48
33
  end
49
34
 
50
35
  def test_1b
51
36
 
52
- h = {
53
- "fx" => "e",
54
- "fy" => "f"
55
- }
56
- do_test(CSV1, h, { :ruby_eval => true }, { "fz" => "7" }, false)
37
+ h = { 'fx' => 'e', 'fy' => 'f' }
38
+ do_test(CSV1, h, { :ruby_eval => true }, { 'fz' => '7' }, false)
57
39
  end
58
40
 
59
41
  def test_1c
60
42
 
61
- h = {
62
- "fx" => "g",
63
- "fy" => "h"
43
+ h = { 'fx' => 'g', 'fy' => 'h' }
44
+ do_test(CSV1, h, { :ruby_eval => true }, { 'fz' => 'gh' }, false)
45
+ end
46
+
47
+ CSV2 = [
48
+ %w{ in:fx in:fy out:fz },
49
+ %w{ a ${fx} 0 },
50
+ %w{ c d ${fx} },
51
+ %w{ e f ${r:3+4} },
52
+ [ 'g', 'h', "${r:'${fx}' + '${fy}'}" ]
53
+ ]
54
+
55
+ def test_with_array_table
56
+
57
+ wi = { 'fx' => 'c', 'fy' => 'd' }
58
+ do_test(CSV2, wi, {}, { 'fz' => 'c' }, false)
59
+ end
60
+
61
+ def test_empty_string_to_float
62
+
63
+ wi = { 'age' => '', 'trait' => 'maniac', 'name' => 'Baumgarter' }
64
+
65
+ table = [
66
+ %w{ in:age in:trait out:salesperson },
67
+ [ '18..35', '', 'Adeslky' ],
68
+ [ '25..35', '', 'Bronco' ],
69
+ [ '36..50', '', 'Espradas' ],
70
+ [ '', 'maniac', 'Korolev' ]
71
+ ]
72
+
73
+ do_test(table, wi, {}, { 'salesperson' => 'Korolev' }, false)
74
+ end
75
+
76
+ def test_vertical_rules
77
+
78
+ table = CSV2.transpose
79
+
80
+ wi = { 'fx' => 'c', 'fy' => 'd' }
81
+ do_test(table, wi, {}, { 'fz' => 'c' }, false)
82
+ end
83
+
84
+ def test_vertical_rules_2
85
+
86
+ table = %{
87
+ in:topic,sports,sports,finance,finance,finance,politics,politics,politics,
88
+ in:region,europe,,america,europe,,asia,america,,
89
+ out:team_member,Alice,Bob,Charly,Donald,Ernest,Fujio,Gilbert,Henry,Zach
64
90
  }
65
- do_test(CSV1, h, { :ruby_eval => true }, { "fz" => "gh" }, false)
91
+
92
+ h = { 'topic' => 'politics', 'region' => 'america' }
93
+ do_test(table, h, {}, { 'team_member' => 'Gilbert' }, false)
66
94
  end
67
95
 
68
96
  end
data/test/eval_test.rb CHANGED
@@ -1,33 +1,25 @@
1
1
 
2
2
  #
3
- # Testing rufus-dollar
4
- #
5
- # John Mettraux at openwfe.org
3
+ # Testing rufus-decision
6
4
  #
7
5
  # Mon Oct 9 22:19:44 JST 2006
8
6
  #
9
7
 
10
8
  require 'test/unit'
11
- require 'rufus/hashes'
12
9
 
13
- #
14
- # testing the 'dollar notation'
15
- #
10
+ require File.dirname(__FILE__) + '/test_base.rb'
16
11
 
17
- class EvalTest < Test::Unit::TestCase
12
+ require 'rufus/hashes'
18
13
 
19
- #def setup
20
- #end
21
14
 
22
- #def teardown
23
- #end
15
+ class EvalTest < Test::Unit::TestCase
24
16
 
25
17
  def test_0
26
18
 
27
- eh = Rufus::EvalHashFilter.new({})
19
+ eh = Rufus::Decision::EvalHashFilter.new({})
28
20
 
29
21
  eh['a'] = :a
30
- eh['b'] = "r:5 * 5"
22
+ eh['b'] = 'r:5 * 5'
31
23
 
32
24
  assert_equal :a, eh['a']
33
25
  assert_equal 25, eh['b']
data/test/goal.csv ADDED
@@ -0,0 +1,3 @@
1
+ age,name,salesperson,trait
2
+ 33,Longbow,adeslky,goofy
3
+ 45,Baumgartner,espadas,maniac
data/test/input.csv ADDED
@@ -0,0 +1,3 @@
1
+ age,trait,name
2
+ 33,goofy,Longbow
3
+ 45,maniac,Baumgartner
data/test/table.csv ADDED
@@ -0,0 +1,9 @@
1
+ in:age,in:trait,out:salesperson
2
+ 18..35,,adeslky
3
+ 25..35,,bronco
4
+ 36..50,,espadas
5
+ 51..78,,thorsten
6
+ 44..120,,ojiisan
7
+ 25..35,rich,kerfelden
8
+ ,cheerful,swanson
9
+ ,maniac,korolev
data/test/test.rb CHANGED
@@ -1,5 +1,9 @@
1
1
 
2
- require 'decision_0_test'
3
- require 'decision_1_test'
4
- require 'eval_test'
2
+ #
3
+ # Testing rufus-decision
4
+ #
5
+ # 2007 something
6
+ #
7
+
8
+ Dir["#{File.dirname(__FILE__)}/*_test.rb"].each { |path| load(path) }
5
9
 
data/test/test_base.rb ADDED
@@ -0,0 +1,51 @@
1
+
2
+ #
3
+ # Testing rufus-decision
4
+ #
5
+ # 2007 something
6
+ #
7
+
8
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
9
+
10
+ require 'rufus/decision'
11
+
12
+
13
+ module DecisionTestMixin
14
+
15
+ protected
16
+
17
+ def do_test (table_data, h, options, expected_result, verbose=false)
18
+
19
+ table = table_data.is_a?(Rufus::Decision::Table) ?
20
+ table_data :
21
+ Rufus::Decision::Table.new(table_data)
22
+
23
+ if verbose
24
+ puts
25
+ puts 'table :'
26
+ puts table.to_csv
27
+ puts
28
+ puts 'before :'
29
+ p h
30
+ end
31
+
32
+ h = table.transform!(h, options)
33
+
34
+ if verbose
35
+ puts
36
+ puts 'after :'
37
+ p h
38
+ end
39
+
40
+ expected_result.each do |k, v|
41
+
42
+ value = h[k]
43
+
44
+ value = value.join(';') if value.is_a?(Array)
45
+
46
+ assert_equal v, value
47
+ end
48
+ end
49
+
50
+ end
51
+
@@ -0,0 +1,64 @@
1
+
2
+ #
3
+ # Testing rufus-decision
4
+ #
5
+ # Thu Apr 23 15:18:15 JST 2009
6
+ #
7
+
8
+ require 'test/unit'
9
+
10
+ require File.dirname(__FILE__) + '/test_base.rb'
11
+
12
+
13
+ class MiscTest < Test::Unit::TestCase
14
+
15
+ def test_transpose_empty_array
16
+
17
+ assert_equal([], Rufus::Decision.transpose([]))
18
+ end
19
+
20
+ def test_transpose_a_to_h
21
+
22
+ assert_equal(
23
+ [
24
+ { 'age' => 33, 'name' => 'Jeff' },
25
+ { 'age' => 35, 'name' => 'John' }
26
+ ],
27
+ Rufus::Decision.transpose([
28
+ [ 'age', 'name' ],
29
+ [ 33, 'Jeff' ],
30
+ [ 35, 'John' ]
31
+ ])
32
+ )
33
+ end
34
+
35
+ def test_transpose_h_to_a
36
+
37
+ assert_equal(
38
+ [
39
+ [ 'age', 'name' ],
40
+ [ 33, 'Jeff' ],
41
+ [ 35, 'John' ]
42
+ ],
43
+ Rufus::Decision.transpose([
44
+ { 'age' => 33, 'name' => 'Jeff' },
45
+ { 'age' => 35, 'name' => 'John' }
46
+ ])
47
+ )
48
+ end
49
+
50
+ def test_transpose_s_to_a
51
+
52
+ assert_equal(
53
+ [
54
+ { 'age' => '33', 'name' => 'Jeff' },
55
+ { 'age' => '35', 'name' => 'John' }
56
+ ],
57
+ Rufus::Decision.transpose(%{
58
+ age,name
59
+ 33,Jeff
60
+ 35,John
61
+ })
62
+ )
63
+ end
64
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-decision
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.0"
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-03 00:00:00 +09:00
12
+ date: 2009-04-25 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -34,8 +34,8 @@ dependencies:
34
34
  version:
35
35
  description:
36
36
  email: jmettraux@gmail.com
37
- executables: []
38
-
37
+ executables:
38
+ - rufus_decide
39
39
  extensions: []
40
40
 
41
41
  extra_rdoc_files:
@@ -43,20 +43,26 @@ extra_rdoc_files:
43
43
  - CHANGELOG.txt
44
44
  - CREDITS.txt
45
45
  files:
46
- - lib/rufus
46
+ - bin/rufus_decide
47
47
  - lib/rufus/decision.rb
48
48
  - lib/rufus/hashes.rb
49
49
  - lib/rufus-decision.rb
50
50
  - test/decision_0_test.rb
51
51
  - test/decision_1_test.rb
52
- - test/dmixin.rb
53
52
  - test/eval_test.rb
53
+ - test/goal.csv
54
+ - test/input.csv
55
+ - test/table.csv
54
56
  - test/test.rb
57
+ - test/test_base.rb
58
+ - test/transpose_test.rb
55
59
  - README.txt
56
60
  - CHANGELOG.txt
57
61
  - CREDITS.txt
58
62
  has_rdoc: true
59
63
  homepage: http://rufus.rubyforge.org/rufus-decision
64
+ licenses: []
65
+
60
66
  post_install_message:
61
67
  rdoc_options: []
62
68
 
@@ -78,9 +84,9 @@ requirements:
78
84
  - rufus-dollar
79
85
  - rufus-treechecker
80
86
  rubyforge_project: rufus
81
- rubygems_version: 1.2.0
87
+ rubygems_version: 1.3.2
82
88
  signing_key:
83
- specification_version: 2
89
+ specification_version: 3
84
90
  summary: CSV based Ruby decision tables
85
91
  test_files:
86
92
  - test/test.rb
data/test/dmixin.rb DELETED
@@ -1,55 +0,0 @@
1
-
2
- #
3
- # Testing rufus-deciision
4
- #
5
- # John Mettraux at openwfe.org
6
- #
7
- # Mon Jan 28 13:22:51 JST 2008
8
- #
9
-
10
- require 'rufus/decision'
11
-
12
-
13
- module DecisionTestMixin
14
-
15
- protected
16
-
17
- def do_test (table_data, h, options, expected_result, verbose=false)
18
-
19
- table = Rufus::DecisionTable.new table_data
20
-
21
- if verbose
22
- puts
23
- puts "table :"
24
- puts table.to_csv
25
- puts
26
- puts "before :"
27
- puts wi
28
- end
29
-
30
- h = table.transform! h, options
31
-
32
- if verbose
33
- puts
34
- puts "after :"
35
- puts h
36
- end
37
-
38
- expected_result.each do |k, v|
39
-
40
- #if wi.attributes[k] != v
41
- #end
42
-
43
- value = h[k]
44
-
45
- value = value.join(';') if value.is_a?(Array)
46
-
47
- assert \
48
- value == v,
49
- "attribute '#{k}' should be set to '#{v}' "+
50
- "but is set to '#{value}'"
51
- end
52
- end
53
-
54
- end
55
-