casegen 2.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/.rubocop.yml +109 -0
  4. data/.ruby-version +1 -1
  5. data/Gemfile +3 -1
  6. data/Gemfile.lock +63 -6
  7. data/README.md +10 -119
  8. data/Rakefile +9 -7
  9. data/bin/casegen +2 -1
  10. data/casegen.gemspec +13 -9
  11. data/doc/bounding_box.rb +37 -0
  12. data/doc/cart.rb +43 -0
  13. data/doc/expect_only.rb +28 -0
  14. data/doc/pricing.rb +50 -0
  15. data/doc/ruby_array.rb +41 -0
  16. data/lib/case_gen/combination.rb +38 -0
  17. data/lib/case_gen/combo_matcher.rb +15 -0
  18. data/lib/case_gen/exclude_rule.rb +50 -0
  19. data/lib/case_gen/expect_rule.rb +24 -0
  20. data/lib/case_gen/generator.rb +40 -0
  21. data/lib/case_gen/output/exclude.rb +6 -0
  22. data/lib/case_gen/output/exclude_as_table.rb +13 -0
  23. data/lib/case_gen/output/exclude_as_text.rb +12 -0
  24. data/lib/case_gen/output/exclude_inline.rb +13 -0
  25. data/lib/case_gen/output/exclude_inline_footnotes.rb +20 -0
  26. data/lib/case_gen/output.rb +66 -0
  27. data/lib/case_gen/rule_description.rb +11 -0
  28. data/lib/case_gen/set.rb +16 -0
  29. data/lib/casegen.rb +15 -183
  30. data/spec/cart_sample_spec.rb +46 -0
  31. data/spec/case_gen/combination_spec.rb +11 -0
  32. data/spec/case_gen/exclude_rule_spec.rb +17 -0
  33. data/spec/exclude_as_table_spec.rb +39 -0
  34. data/spec/exclude_as_text_spec.rb +58 -0
  35. data/spec/exclude_inline_footnotes_spec.rb +58 -0
  36. data/spec/exclude_inline_spec.rb +50 -0
  37. data/spec/expect_only_spec.rb +30 -0
  38. data/spec/spec_helper.rb +113 -0
  39. metadata +103 -40
  40. data/.idea/encodings.xml +0 -5
  41. data/.idea/misc.xml +0 -5
  42. data/.idea/modules.xml +0 -9
  43. data/.idea/vcs.xml +0 -7
  44. data/doc/calc.sample.txt +0 -13
  45. data/doc/cart.sample.rb +0 -3
  46. data/doc/cart.sample.txt +0 -33
  47. data/doc/ruby_array.sample.rb +0 -26
  48. data/lib/agents/sets/enum/by.rb +0 -244
  49. data/lib/agents/sets/enum/cluster.rb +0 -164
  50. data/lib/agents/sets/enum/inject.rb +0 -50
  51. data/lib/agents/sets/enum/nest.rb +0 -117
  52. data/lib/agents/sets/enum/op.rb +0 -283
  53. data/lib/agents/sets/enum/pipe.rb +0 -160
  54. data/lib/agents/sets/enum/tree.rb +0 -442
  55. data/lib/agents/sets.rb +0 -313
  56. data/test/agents/console_output_test.rb +0 -27
  57. data/test/agents/sets.test.rb +0 -227
  58. data/test/agents_test.rb +0 -41
  59. data/test/casegen.tests.rb +0 -0
  60. data/test/parser_test.rb +0 -163
  61. data/test/test_helper.rb +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee14f6a724a837cba03b3ec269718713400ad45e2b49b11c3e9022abe56e4587
4
- data.tar.gz: 1b2ccea7698217314e4722f4c3543e2b54566e6d2c003d3f00e7942b46802962
3
+ metadata.gz: 5bb2b1a19cbb5b53da68ce37c7b2c9ff99f9105636520405c0ec18e47c7aed2c
4
+ data.tar.gz: a7e541670d1fd620b92069310bded11e8f182aea34fcd3e9ec01d09c0dd8e66d
5
5
  SHA512:
6
- metadata.gz: a3b8a1f42c2bff9fa37a147e96807123afa94941c41588f00903f8cb82541bd90ca0ab72b4fdf53dd319d9fb7e557cbf39485bcaa38b24b69870eb1e193c5470
7
- data.tar.gz: 7fb847d1589799ef522a3fde0ff1f8d6322c67045fb555ed809baa98432b66f86b07cb339ddfc703e232e3a905b71721b85eb1add2bf8bada8704e1a7106b78f
6
+ metadata.gz: e1b6a5a094ba06210a78f9193f46fac19c1331a7d265364da322a6dc470b5c8b4cf32e5b7d284d2ad0982d0a87297dfbda41853b89eda23535c1d0ed61db7333
7
+ data.tar.gz: ed7a0b9ba8572d495b49ff9d5d7baf74ba04cd75aae70ee062eb7f4bdbbcedde460758868bc12bf1db53dece726809022bb2d38a8f2c3bab92f0f6b59521d30e
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,109 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rake
4
+ - rubocop-rspec
5
+
6
+ AllCops:
7
+ TargetRubyVersion: 2.5
8
+ NewCops: disable
9
+ Exclude:
10
+ - bin/*
11
+
12
+ Layout/ClassStructure:
13
+ Enabled: true
14
+ Categories:
15
+ module_inclusion:
16
+ - include
17
+ - prepend
18
+ - extend
19
+ ExpectedOrder:
20
+ - module_inclusion
21
+ - public_class_methods
22
+ - initializer
23
+ - public_methods
24
+ - protected_methods
25
+ - private_methods
26
+
27
+ Layout/DotPosition:
28
+ EnforcedStyle: trailing
29
+
30
+ Layout/LineLength:
31
+ Enabled: false
32
+ Max: 120
33
+ AllowHeredoc: true
34
+ AllowURI: true
35
+ URISchemes: http, https
36
+
37
+ Layout/MultilineMethodCallIndentation:
38
+ Enabled: false
39
+
40
+ Layout/SpaceInsideHashLiteralBraces:
41
+ Enabled: false
42
+
43
+ Metrics:
44
+ Enabled: true
45
+
46
+ Metrics/AbcSize:
47
+ Max: 20
48
+
49
+ Metrics/BlockLength:
50
+ Exclude:
51
+ - 'Rakefile'
52
+ - '**/*.rake'
53
+ - 'spec/**/*.rb'
54
+ - 'test/**/*.rb'
55
+ IgnoredMethods: ['included', 'namespace']
56
+
57
+ Metrics/ClassLength:
58
+ Exclude:
59
+ - 'Rakefile'
60
+ - 'spec/**/*.rb'
61
+ - 'test/**/*.rb'
62
+
63
+ Metrics/MethodLength:
64
+ CountComments: false # count full line comments?
65
+ Max: 15
66
+
67
+ Naming/MemoizedInstanceVariableName:
68
+ Enabled: false
69
+
70
+ RSpec/DescribeClass:
71
+ Enabled: false
72
+
73
+ Style/BlockComments:
74
+ Enabled: false
75
+
76
+ Style/Documentation:
77
+ Enabled: false
78
+
79
+ Style/DocumentationMethod:
80
+ Enabled: false
81
+
82
+ Style/FrozenStringLiteralComment:
83
+ EnforcedStyle: always
84
+ Enabled: true
85
+
86
+ Style/GuardClause:
87
+ Enabled: false
88
+
89
+ Style/MultilineBlockChain:
90
+ Enabled: false
91
+
92
+ # Technically this performs better, and I got no problem with it.
93
+ Style/ParallelAssignment:
94
+ Enabled: false
95
+
96
+ Style/RedundantSelf:
97
+ Enabled: false
98
+
99
+ Style/TrailingCommaInArrayLiteral:
100
+ Enabled: false
101
+
102
+ Style/TrailingCommaInHashLiteral:
103
+ Enabled: false
104
+
105
+ Style/WhenThen:
106
+ Enabled: true
107
+
108
+ Style/WordArray:
109
+ Enabled: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.1
1
+ 3.3.3
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
- gemspec
5
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,25 +1,82 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- casegen (2.0.0)
4
+ casegen (3.0.1)
5
5
  tablesmith
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- minitest (5.11.3)
11
- rake (12.3.1)
12
- tablesmith (0.4.1)
10
+ ast (2.4.3)
11
+ diff-lcs (1.6.2)
12
+ json (2.12.2)
13
+ language_server-protocol (3.17.0.5)
14
+ lint_roller (1.1.0)
15
+ parallel (1.27.0)
16
+ parser (3.3.8.0)
17
+ ast (~> 2.4.1)
18
+ racc
19
+ prism (1.4.0)
20
+ racc (1.8.1)
21
+ rainbow (3.1.1)
22
+ rake (13.3.0)
23
+ regexp_parser (2.10.0)
24
+ rspec (3.13.1)
25
+ rspec-core (~> 3.13.0)
26
+ rspec-expectations (~> 3.13.0)
27
+ rspec-mocks (~> 3.13.0)
28
+ rspec-core (3.13.4)
29
+ rspec-support (~> 3.13.0)
30
+ rspec-expectations (3.13.5)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.13.0)
33
+ rspec-mocks (3.13.5)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.13.0)
36
+ rspec-support (3.13.4)
37
+ rubocop (1.76.0)
38
+ json (~> 2.3)
39
+ language_server-protocol (~> 3.17.0.2)
40
+ lint_roller (~> 1.1.0)
41
+ parallel (~> 1.10)
42
+ parser (>= 3.3.0.2)
43
+ rainbow (>= 2.2.2, < 4.0)
44
+ regexp_parser (>= 2.9.3, < 3.0)
45
+ rubocop-ast (>= 1.45.0, < 2.0)
46
+ ruby-progressbar (~> 1.7)
47
+ unicode-display_width (>= 2.4.0, < 4.0)
48
+ rubocop-ast (1.45.0)
49
+ parser (>= 3.3.7.2)
50
+ prism (~> 1.4)
51
+ rubocop-performance (1.25.0)
52
+ lint_roller (~> 1.1)
53
+ rubocop (>= 1.75.0, < 2.0)
54
+ rubocop-ast (>= 1.38.0, < 2.0)
55
+ rubocop-rake (0.7.1)
56
+ lint_roller (~> 1.1)
57
+ rubocop (>= 1.72.1)
58
+ rubocop-rspec (3.6.0)
59
+ lint_roller (~> 1.1)
60
+ rubocop (~> 1.72, >= 1.72.1)
61
+ ruby-progressbar (1.13.0)
62
+ tablesmith (0.7.0)
13
63
  text-table
14
64
  text-table (1.2.4)
65
+ unicode-display_width (3.1.4)
66
+ unicode-emoji (~> 4.0, >= 4.0.4)
67
+ unicode-emoji (4.0.4)
15
68
 
16
69
  PLATFORMS
17
70
  ruby
18
71
 
19
72
  DEPENDENCIES
20
73
  casegen!
21
- minitest
22
74
  rake
75
+ rspec
76
+ rubocop
77
+ rubocop-performance
78
+ rubocop-rake
79
+ rubocop-rspec
23
80
 
24
81
  BUNDLED WITH
25
- 1.17.3
82
+ 2.6.9
data/README.md CHANGED
@@ -1,132 +1,23 @@
1
1
  # CaseGen
2
2
 
3
- CaseGen is a small Ruby external DSL for generating combinations of variables,
4
- optionally restricted by a set of rules.
3
+ CaseGen is a small Ruby gem for generating combinations of variables, optionally
4
+ restricted by a set of rules.
5
5
 
6
6
  ## Usage
7
7
 
8
- This input file:
8
+ The [`doc`](/doc) folder has a few examples demonstrating how you can use this
9
+ gem. The [`specs`](/spec) also demonstrate various input and output options.
9
10
 
10
- sets
11
- ------------
12
- payment: Credit, Check, Online Bank
13
- amount: 100, 1,000, 10,000
14
- shipping: Ground, Air
15
- ship to country: US, Outside US
16
- bill to country: US, Outside US
17
-
18
-
19
- rules(sets)
20
- ---------------------------
21
- exclude shipping = Ground AND ship to country = Outside US
22
- Our ground shipper will only ship things within the US.
23
-
24
- exclude payment = Check AND bill to country == Outside US
25
- Our bank will not accept checks written from banks outside the US.
26
-
27
- exclude payment = Online Bank AND amount == 1,000
28
- exclude payment = Online Bank AND amount == 10,000
29
- While the online bank will process amounts > $1,000, we've experienced
30
- occasional problems with their services and have had to write off some
31
- transactions, so we no longer allow this payment option for amounts greater
32
- than $1,000
33
-
34
- exclude ship to country = US AND bill to country = Outside US
35
- If we're shipping to the US, billing party cannot be outside US
36
-
37
-
38
- console(rules)
39
- ----------
40
11
 
12
+ ## Breaking Changes in 3.0
41
13
 
42
- produces this output:
43
-
44
- +-------------+--------+----------+-----------------+-----------------+
45
- | payment | amount | shipping | ship to country | bill to country |
46
- +-------------+--------+----------+-----------------+-----------------+
47
- | Credit | 100 | Ground | US | US |
48
- | Credit | 100 | Air | US | US |
49
- | Credit | 100 | Air | Outside US | US |
50
- | Credit | 100 | Air | Outside US | Outside US |
51
- | Credit | 1,000 | Ground | US | US |
52
- | Credit | 1,000 | Air | US | US |
53
- | Credit | 1,000 | Air | Outside US | US |
54
- | Credit | 1,000 | Air | Outside US | Outside US |
55
- | Credit | 10,000 | Ground | US | US |
56
- | Credit | 10,000 | Air | US | US |
57
- | Credit | 10,000 | Air | Outside US | US |
58
- | Credit | 10,000 | Air | Outside US | Outside US |
59
- | Check | 100 | Ground | US | US |
60
- | Check | 100 | Air | US | US |
61
- | Check | 100 | Air | Outside US | US |
62
- | Check | 1,000 | Ground | US | US |
63
- | Check | 1,000 | Air | US | US |
64
- | Check | 1,000 | Air | Outside US | US |
65
- | Check | 10,000 | Ground | US | US |
66
- | Check | 10,000 | Air | US | US |
67
- | Check | 10,000 | Air | Outside US | US |
68
- | Online Bank | 100 | Ground | US | US |
69
- | Online Bank | 100 | Air | US | US |
70
- | Online Bank | 100 | Air | Outside US | US |
71
- | Online Bank | 100 | Air | Outside US | Outside US |
72
- +-------------+--------+----------+-----------------+-----------------+
73
-
74
- exclude shipping = Ground AND ship to country = Outside US
75
- Our ground shipper will only ship things within the US.
76
-
77
- exclude payment = Check AND bill to country == Outside US
78
- Our bank will not accept checks written from banks outside the US.
79
-
80
- exclude payment = Online Bank AND amount == 1,000
81
-
82
- exclude payment = Online Bank AND amount == 10,000
83
- While the online bank will process amounts > $1,000, we've experienced
84
- occasional problems with their services and have had to write off some
85
- transactions, so we no longer allow this payment option for amounts greater
86
- than $1,000
87
-
88
- exclude ship to country = US AND bill to country = Outside US
89
- If we're shipping to the US, billing party cannot be outside US
90
-
91
- If you pull the source locally, you can execute this:
14
+ Versions 1 and 2 were based on a DSL format. Version 3.0 removed the DSL
15
+ to just use plain Ruby.
92
16
 
93
- casegen doc/cart.sample.txt
94
-
95
17
  ## FAQ
96
18
 
97
- How can I use this lib inside another Ruby file, instead of having a separate
98
- input file?
99
-
100
- sample.rb:
101
-
102
- require "bundler/inline"
103
-
104
- gemfile do
105
- source "https://rubygems.org"
106
- gem "casegen", "~> 2.0"
107
- end
108
-
109
- require 'casegen'
110
-
111
- CLabs::CaseGen::CaseGen.new(DATA.read)
112
-
113
- __END__
114
-
115
- sets
116
- ----
117
- a: 1, 2
118
- b: 3, 4
119
-
120
- rules(sets)
121
- -----------
122
- exclude a = 1
123
-
124
- console(rules)
125
- --------------
126
-
127
-
128
19
  ### Are there other tools similar to CaseGen?
129
20
 
130
- <a href="http://code.google.com/p/tcases/">tcases</a> is one to check out.
131
- Another is <a href="http://www.satisfice.com/tools.shtml">AllPairs</a> by James
132
- Bach.
21
+ <a href="https://github.com/cornutum/tcases">tcases</a> is one to check out.
22
+ Another is <a href="https://www.satisfice.com/download/allpairs">AllPairs</a> by
23
+ James Bach.
data/Rakefile CHANGED
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
 
3
- require 'rake/testtask'
5
+ require 'rspec/core/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ require 'rubocop/rake_task'
4
10
 
5
- desc 'Run tests'
6
- Rake::TestTask.new do |t|
7
- t.pattern = 'test/**/*test*.rb'
8
- # t.verbose = true
9
- end
11
+ RuboCop::RakeTask.new
10
12
 
11
- task default: :test
13
+ task default: [:spec, 'rubocop:auto_correct']
data/bin/casegen CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  gem 'casegen'
4
5
  require 'casegen'
5
6
 
6
- CLabs::CaseGen::CaseGen.new(File.read(ARGV[0]))
7
+ CLabs::CaseGen::CaseGen.new(File.read(ARGV[0]))
data/casegen.gemspec CHANGED
@@ -1,26 +1,30 @@
1
- lib = File.expand_path('lib', __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'casegen'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/casegen'
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = 'casegen'
7
- gem.version = CLabs::CaseGen::CaseGen.version
7
+ gem.version = '3.0.1'
8
8
  gem.authors = ['chrismo']
9
9
  gem.email = 'chrismo@clabs.org'
10
- gem.description = 'Simple Ruby DSL to generate use cases restricted by sets of rules'
11
- gem.summary = 'Simple Ruby DSL to generate use cases restricted by sets of rules'
10
+ gem.description = 'Simple tool to generate use cases restricted by sets of rules'
11
+ gem.summary = 'Simple tool to generate use cases restricted by sets of rules'
12
12
  gem.homepage = 'https://github.com/chrismo/casegen'
13
13
  gem.license = 'MIT'
14
14
 
15
- gem.files = `git ls-files`.split($/)
15
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
16
16
  gem.executables = 'casegen'
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ['lib']
19
19
 
20
- gem.required_ruby_version = '~> 2.3'
20
+ gem.required_ruby_version = '>= 2.5'
21
21
 
22
22
  gem.add_dependency 'tablesmith'
23
23
 
24
- gem.add_development_dependency 'minitest'
25
24
  gem.add_development_dependency 'rake'
25
+ gem.add_development_dependency 'rspec'
26
+ gem.add_development_dependency 'rubocop'
27
+ gem.add_development_dependency 'rubocop-performance'
28
+ gem.add_development_dependency 'rubocop-rake'
29
+ gem.add_development_dependency 'rubocop-rspec'
26
30
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/casegen'
4
+
5
+ # Presuming a 300x300 bounding box, we need images to test edge cases.
6
+
7
+ bounding_box_relation = %w[inside outside]
8
+
9
+ sets = {
10
+ width: bounding_box_relation,
11
+ height: bounding_box_relation,
12
+ aspect: %w[wide tall],
13
+ result: [:expect]
14
+ }
15
+
16
+ rules = {
17
+ exclude: [
18
+ {width: 'inside', height: 'outside', aspect: 'wide',
19
+ note: 'a narrower image cannot have a wide aspect'},
20
+ {width: 'outside', height: 'inside', aspect: 'tall',
21
+ note: 'a shorter image cannot have a tall aspect'},
22
+ ],
23
+ expect: [
24
+ {width: 'inside', height: 'inside', aspect: 'wide', result: '200x100'},
25
+ {width: 'inside', height: 'inside', aspect: 'tall', result: '100x200'},
26
+ {width: 'inside', height: 'outside', aspect: 'tall', result: '100x400'},
27
+ {width: 'outside', height: 'inside', aspect: 'wide', result: '400x100'},
28
+ {width: 'outside', height: 'outside', aspect: 'wide', result: '500x400'},
29
+ {width: 'outside', height: 'outside', aspect: 'tall', result: '400x500'},
30
+ ]
31
+ }
32
+
33
+ if __FILE__ == $PROGRAM_NAME
34
+ puts CaseGen.generate(sets, rules, :exclude_as_table).to_s
35
+ else
36
+ Fixtures.add(:box, sets, rules)
37
+ end
data/doc/cart.rb ADDED
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/casegen'
4
+
5
+ sets = {
6
+ payment: ['Credit', 'Check', 'Online Bank'],
7
+ amount: [100, 1_000, 10_000],
8
+ shipping: ['Ground', 'Air'],
9
+ ship_to_country: ['US', 'Outside US'],
10
+ bill_to_country: ['US', 'Outside US']
11
+ }
12
+
13
+ rules = {
14
+ exclude: [
15
+ {
16
+ criteria: %(shipping == "Ground" && ship_to_country == "Outside US" ),
17
+ description: 'Our ground shipper will only ship things within the US',
18
+ },
19
+ {
20
+ criteria: -> { payment == 'Check' && bill_to_country == 'Outside US' },
21
+ description: 'Our bank will not accept checks written from banks outside the US.',
22
+ },
23
+ {
24
+ criteria: -> { payment == 'Online Bank' && amount >= 1_000 },
25
+ description: <<~_,
26
+ While the online bank will process amounts > $1,000, we've experienced
27
+ occasional problems with their services and have had to write off some
28
+ transactions, so we no longer allow this payment option for amounts
29
+ greater than $1,000.
30
+ _
31
+ },
32
+ {
33
+ criteria: -> { ship_to_country == 'US' && bill_to_country == 'Outside US' },
34
+ description: "If we're shipping to the US, billing party cannot be outside US"
35
+ },
36
+ ]
37
+ }
38
+
39
+ if __FILE__ == $PROGRAM_NAME
40
+ puts CaseGen.generate(sets, rules, :exclude_as_text).to_s
41
+ else
42
+ Fixtures.add(:cart, sets, rules)
43
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/casegen'
4
+
5
+ sets = {
6
+ duration: [12, 24, 36, 60],
7
+ unit: [60, 3600],
8
+ result: [:expect]
9
+ }
10
+
11
+ rules = {
12
+ expect: [
13
+ {duration: 12, unit: 60, result: '12m'},
14
+ {duration: 12, unit: 3600, result: '12h'},
15
+ {duration: 24, unit: 60, result: '24m'},
16
+ {duration: 24, unit: 3600, result: '1d'},
17
+ {duration: 36, unit: 60, result: '36m'},
18
+ {duration: 36, unit: 3600, result: '1d 12h'},
19
+ {duration: 60, unit: 60, result: '1h'},
20
+ {duration: 60, unit: 3600, result: '2d 12h'},
21
+ ]
22
+ }
23
+
24
+ if __FILE__ == $PROGRAM_NAME
25
+ puts CaseGen.generate(sets, rules, :exclude_inline).to_s
26
+ else
27
+ Fixtures.add(:duration, sets, rules)
28
+ end
data/doc/pricing.rb ADDED
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/casegen'
4
+
5
+ sets = {
6
+ subtotal: [25, 75, 200],
7
+ discount: %w[0% 10% 20%],
8
+ promo: %w[none apr fall],
9
+ total: [:expect]
10
+ }
11
+
12
+ rules = {
13
+ exclude: [
14
+ {
15
+ criteria: %(subtotal < 100 && discount == '20%'),
16
+ description: 'Total must be above $100 to apply the 20% discount',
17
+ },
18
+ {
19
+ criteria: %((subtotal < 50) && discount == '10%'),
20
+ note: 'Total must be above $50 to apply the 10% discount',
21
+ },
22
+ {
23
+ criteria: %(discount != '20%' && subtotal == 200),
24
+ reason: 'Orders over 100 automatically get 20% discount',
25
+ },
26
+ {
27
+ criteria: %(discount != '10%' && subtotal == 75),
28
+ reason: 'Orders between 50 and 100 automatically get 10% discount',
29
+ },
30
+ {
31
+ criteria: %(discount == '20%' && promo != 'none'),
32
+ reason: '20% discount cannot be combined with promo',
33
+ },
34
+ ],
35
+ expect: [
36
+ {subtotal: 25, promo: 'none', total: '25.00'},
37
+ {subtotal: 25, promo: 'apr', total: '17.50', reason: 'apr promo is 30%'},
38
+ {subtotal: 25, promo: 'fall', total: '16.25', note: 'fall promo is 35%'},
39
+ {subtotal: 75, promo: 'none', total: '67.50', note: '10% discount'},
40
+ {subtotal: 75, promo: 'apr', total: '47.25', reason: '10% + apr promo is 30%'},
41
+ {subtotal: 75, promo: 'fall', total: '43.88', note: '10% + fall promo is 35%'},
42
+ {subtotal: 200, promo: 'none', total: '160.00', note: '20% discount'},
43
+ ]
44
+ }
45
+
46
+ if __FILE__ == $PROGRAM_NAME
47
+ puts CaseGen.generate(sets, rules, :exclude_as_text)
48
+ else
49
+ Fixtures.add(:pricing, sets, rules)
50
+ end
data/doc/ruby_array.rb ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/case_gen'
4
+
5
+ raise "This doesn't currently work. Do I even want to keep it?"
6
+
7
+ # CLabs::CaseGen::CaseGen.new(DATA.read)
8
+
9
+ # Outputs
10
+ #
11
+ # DataSubmitCase = Struct.new(:role, :authorization_code, :submit_enabled)
12
+ #
13
+ # cases = [DataSubmitCase.new("admin", "none", "true"),
14
+ # DataSubmitCase.new("admin", "invalid", "true"),
15
+ # DataSubmitCase.new("admin", "valid", "true"),
16
+ # DataSubmitCase.new("standard", "none", "false"),
17
+ # DataSubmitCase.new("standard", "invalid", "false"),
18
+ # DataSubmitCase.new("standard", "valid", "true")]
19
+
20
+ __END__
21
+
22
+ sets
23
+ ----
24
+ role: admin, standard
25
+ authorization code: none, invalid, valid
26
+ submit enabled: true, false
27
+
28
+ rules(sets)
29
+ -----------
30
+ exclude role = admin AND submit enabled = false
31
+ Admin role can always submit
32
+
33
+ exclude role = standard AND authorization code = none AND submit enabled = true
34
+ exclude role = standard AND authorization code = invalid AND submit enabled = true
35
+ exclude role = standard AND authorization code = valid AND submit enabled = false
36
+ Standard role can only submit when authorization code is valid
37
+
38
+
39
+ ruby_array(rules)
40
+ -------------
41
+ DataSubmitCase
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CaseGen
4
+ class Combination
5
+ attr_reader :names, :excluded_by_rule
6
+
7
+ def initialize(hash_pairs)
8
+ @names = hash_pairs.map do |h|
9
+ k = h.first.first
10
+ v = h.first.last
11
+ append(k, v)
12
+ k
13
+ end
14
+ end
15
+
16
+ def hash_row
17
+ {}.tap do |h|
18
+ @names.each do |ivar|
19
+ h[ivar] = instance_variable_get("@#{ivar}")
20
+ end
21
+ end
22
+ end
23
+
24
+ def append(key, value)
25
+ @names << key if defined?(@names)
26
+ instance_variable_set("@#{key}", value)
27
+ self.class.attr_accessor key
28
+ end
29
+
30
+ def exclude_with(rule)
31
+ @excluded_by_rule = rule
32
+ end
33
+
34
+ def excluded?
35
+ !@excluded_by_rule.nil?
36
+ end
37
+ end
38
+ end