casegen 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
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 +51 -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 +101 -35
  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
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require_relative '../doc/pricing'
5
+
6
+ RSpec.describe 'Exclude inline' do
7
+ let(:expected_table) do
8
+ <<~_
9
+ +----------+----------+-------+--------+----------------------------------------------------------+
10
+ | subtotal | discount | promo | total | exclude |
11
+ +----------+----------+-------+--------+----------------------------------------------------------+
12
+ | 25 | 0% | none | 25.00 | |
13
+ | 25 | 0% | apr | 17.50 | |
14
+ | 25 | 0% | fall | 16.25 | |
15
+ | 25 | 10% | none | | Total must be above $50 to apply the 10% discount |
16
+ | 25 | 10% | apr | | Total must be above $50 to apply the 10% discount |
17
+ | 25 | 10% | fall | | Total must be above $50 to apply the 10% discount |
18
+ | 25 | 20% | none | | Total must be above $100 to apply the 20% discount |
19
+ | 25 | 20% | apr | | Total must be above $100 to apply the 20% discount |
20
+ | 25 | 20% | fall | | Total must be above $100 to apply the 20% discount |
21
+ | 75 | 0% | none | | Orders between 50 and 100 automatically get 10% discount |
22
+ | 75 | 0% | apr | | Orders between 50 and 100 automatically get 10% discount |
23
+ | 75 | 0% | fall | | Orders between 50 and 100 automatically get 10% discount |
24
+ | 75 | 10% | none | 67.50 | |
25
+ | 75 | 10% | apr | 47.25 | |
26
+ | 75 | 10% | fall | 43.88 | |
27
+ | 75 | 20% | none | | Total must be above $100 to apply the 20% discount |
28
+ | 75 | 20% | apr | | Total must be above $100 to apply the 20% discount |
29
+ | 75 | 20% | fall | | Total must be above $100 to apply the 20% discount |
30
+ | 200 | 0% | none | | Orders over 100 automatically get 20% discount |
31
+ | 200 | 0% | apr | | Orders over 100 automatically get 20% discount |
32
+ | 200 | 0% | fall | | Orders over 100 automatically get 20% discount |
33
+ | 200 | 10% | none | | Orders over 100 automatically get 20% discount |
34
+ | 200 | 10% | apr | | Orders over 100 automatically get 20% discount |
35
+ | 200 | 10% | fall | | Orders over 100 automatically get 20% discount |
36
+ | 200 | 20% | none | 160.00 | |
37
+ | 200 | 20% | apr | | 20% discount cannot be combined with promo |
38
+ | 200 | 20% | fall | | 20% discount cannot be combined with promo |
39
+ +----------+----------+-------+--------+----------------------------------------------------------+
40
+ _
41
+ end
42
+
43
+ let(:sets) { Fixtures[:pricing][:sets] }
44
+ let(:rules) { Fixtures[:pricing][:rules] }
45
+
46
+ it 'output' do
47
+ result = CaseGen.generate(sets, rules, :exclude_inline)
48
+ expect(result).to eq expected_table
49
+ end
50
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require_relative '../doc/expect_only'
5
+
6
+ RSpec.describe 'Exclude as table' do
7
+ let(:expected_combo_table) do
8
+ <<~_
9
+ +----------+------+--------+
10
+ | duration | unit | result |
11
+ +----------+------+--------+
12
+ | 12 | 60 | 12m |
13
+ | 12 | 3600 | 12h |
14
+ | 24 | 60 | 24m |
15
+ | 24 | 3600 | 1d |
16
+ | 36 | 60 | 36m |
17
+ | 36 | 3600 | 1d 12h |
18
+ | 60 | 60 | 1h |
19
+ | 60 | 3600 | 2d 12h |
20
+ +----------+------+--------+
21
+ _
22
+ end
23
+
24
+ let(:fix) { Fixtures[:duration] }
25
+
26
+ it 'output' do
27
+ output = CaseGen.generate(fix[:sets], fix[:rules], :exclude_inline)
28
+ expect(output.to_s).to eq expected_combo_table
29
+ end
30
+ end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # it.
16
+ #
17
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
18
+ RSpec.configure do |config|
19
+ # rspec-expectations config goes here. You can use an alternate
20
+ # assertion/expectation library such as wrong or the stdlib/minitest
21
+ # assertions if you prefer.
22
+ config.expect_with :rspec do |expectations|
23
+ # This option will default to `true` in RSpec 4. It makes the `description`
24
+ # and `failure_message` of custom matchers include text for helper methods
25
+ # defined using `chain`, e.g.:
26
+ # be_bigger_than(2).and_smaller_than(4).description
27
+ # # => "be bigger than 2 and smaller than 4"
28
+ # ...rather than:
29
+ # # => "be bigger than 2"
30
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
31
+ end
32
+
33
+ # rspec-mocks config goes here. You can use an alternate test double
34
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
35
+ config.mock_with :rspec do |mocks|
36
+ # Prevents you from mocking or stubbing a method that does not exist on
37
+ # a real object. This is generally recommended, and will default to
38
+ # `true` in RSpec 4.
39
+ mocks.verify_partial_doubles = true
40
+ end
41
+
42
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
43
+ # have no way to turn it off -- the option exists only for backwards
44
+ # compatibility in RSpec 3). It causes shared context metadata to be
45
+ # inherited by the metadata hash of host groups and examples, rather than
46
+ # triggering implicit auto-inclusion in groups with matching metadata.
47
+ config.shared_context_metadata_behavior = :apply_to_host_groups
48
+
49
+ # The settings below are suggested to provide a good initial experience
50
+ # with RSpec, but feel free to customize to your heart's content.
51
+ =begin
52
+ # This allows you to limit a spec run to individual examples or groups
53
+ # you care about by tagging them with `:focus` metadata. When nothing
54
+ # is tagged with `:focus`, all examples get run. RSpec also provides
55
+ # aliases for `it`, `describe`, and `context` that include `:focus`
56
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
57
+ config.filter_run_when_matching :focus
58
+
59
+ # Allows RSpec to persist some state between runs in order to support
60
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
61
+ # you configure your source control system to ignore this file.
62
+ config.example_status_persistence_file_path = "spec/examples.txt"
63
+
64
+ # Limits the available syntax to the non-monkey patched syntax that is
65
+ # recommended. For more details, see:
66
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
67
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
68
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
69
+ config.disable_monkey_patching!
70
+
71
+ # This setting enables warnings. It's recommended, but in some cases may
72
+ # be too noisy due to issues in dependencies.
73
+ config.warnings = true
74
+
75
+ # Many RSpec users commonly either run the entire suite or an individual
76
+ # file, and it's useful to allow more verbose output when running an
77
+ # individual spec file.
78
+ if config.files_to_run.one?
79
+ # Use the documentation formatter for detailed output,
80
+ # unless a formatter has already been configured
81
+ # (e.g. via a command-line flag).
82
+ config.default_formatter = "doc"
83
+ end
84
+
85
+ # Print the 10 slowest examples and example groups at the
86
+ # end of the spec run, to help surface which specs are running
87
+ # particularly slow.
88
+ config.profile_examples = 10
89
+
90
+ # Run specs in random order to surface order dependencies. If you find an
91
+ # order dependency and want to debug it, you can fix the order by providing
92
+ # the seed, which is printed after each run.
93
+ # --seed 1234
94
+ config.order = :random
95
+
96
+ # Seed global randomization in this process using the `--seed` CLI option.
97
+ # Setting this allows you to use `--seed` to deterministically reproduce
98
+ # test failures related to randomization by passing the same `--seed` value
99
+ # as the one that triggered the failure.
100
+ Kernel.srand config.seed
101
+ =end
102
+ end
103
+
104
+ class Fixtures
105
+ def self.add(name, sets, rules)
106
+ @fixtures ||= {}
107
+ @fixtures[name] = {sets: sets, rules: rules}
108
+ end
109
+
110
+ def self.[](name)
111
+ @fixtures[name]
112
+ end
113
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casegen
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - chrismo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-05 00:00:00.000000000 Z
11
+ date: 2021-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tablesmith
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: minitest
28
+ name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,63 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-performance
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rspec
43
99
  requirement: !ruby/object:Gem::Requirement
44
100
  requirements:
45
101
  - - ">="
@@ -52,7 +108,7 @@ dependencies:
52
108
  - - ">="
53
109
  - !ruby/object:Gem::Version
54
110
  version: '0'
55
- description: Simple Ruby DSL to generate use cases restricted by sets of rules
111
+ description: Simple tool to generate use cases restricted by sets of rules
56
112
  email: chrismo@clabs.org
57
113
  executables:
58
114
  - casegen
@@ -60,10 +116,8 @@ extensions: []
60
116
  extra_rdoc_files: []
61
117
  files:
62
118
  - ".gitignore"
63
- - ".idea/encodings.xml"
64
- - ".idea/misc.xml"
65
- - ".idea/modules.xml"
66
- - ".idea/vcs.xml"
119
+ - ".rspec"
120
+ - ".rubocop.yml"
67
121
  - ".ruby-version"
68
122
  - Gemfile
69
123
  - Gemfile.lock
@@ -73,25 +127,34 @@ files:
73
127
  - TODO
74
128
  - bin/casegen
75
129
  - casegen.gemspec
76
- - doc/calc.sample.txt
77
- - doc/cart.sample.rb
78
- - doc/cart.sample.txt
79
- - doc/ruby_array.sample.rb
80
- - lib/agents/sets.rb
81
- - lib/agents/sets/enum/by.rb
82
- - lib/agents/sets/enum/cluster.rb
83
- - lib/agents/sets/enum/inject.rb
84
- - lib/agents/sets/enum/nest.rb
85
- - lib/agents/sets/enum/op.rb
86
- - lib/agents/sets/enum/pipe.rb
87
- - lib/agents/sets/enum/tree.rb
130
+ - doc/bounding_box.rb
131
+ - doc/cart.rb
132
+ - doc/expect_only.rb
133
+ - doc/pricing.rb
134
+ - doc/ruby_array.rb
135
+ - lib/case_gen/combination.rb
136
+ - lib/case_gen/combo_matcher.rb
137
+ - lib/case_gen/exclude_rule.rb
138
+ - lib/case_gen/expect_rule.rb
139
+ - lib/case_gen/generator.rb
140
+ - lib/case_gen/output.rb
141
+ - lib/case_gen/output/exclude.rb
142
+ - lib/case_gen/output/exclude_as_table.rb
143
+ - lib/case_gen/output/exclude_as_text.rb
144
+ - lib/case_gen/output/exclude_inline.rb
145
+ - lib/case_gen/output/exclude_inline_footnotes.rb
146
+ - lib/case_gen/rule_description.rb
147
+ - lib/case_gen/set.rb
88
148
  - lib/casegen.rb
89
- - test/agents/console_output_test.rb
90
- - test/agents/sets.test.rb
91
- - test/agents_test.rb
92
- - test/casegen.tests.rb
93
- - test/parser_test.rb
94
- - test/test_helper.rb
149
+ - spec/cart_sample_spec.rb
150
+ - spec/case_gen/combination_spec.rb
151
+ - spec/case_gen/exclude_rule_spec.rb
152
+ - spec/exclude_as_table_spec.rb
153
+ - spec/exclude_as_text_spec.rb
154
+ - spec/exclude_inline_footnotes_spec.rb
155
+ - spec/exclude_inline_spec.rb
156
+ - spec/expect_only_spec.rb
157
+ - spec/spec_helper.rb
95
158
  homepage: https://github.com/chrismo/casegen
96
159
  licenses:
97
160
  - MIT
@@ -104,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
167
  requirements:
105
168
  - - "~>"
106
169
  - !ruby/object:Gem::Version
107
- version: '2.3'
170
+ version: '2.5'
108
171
  required_rubygems_version: !ruby/object:Gem::Requirement
109
172
  requirements:
110
173
  - - ">="
@@ -114,11 +177,14 @@ requirements: []
114
177
  rubygems_version: 3.0.3
115
178
  signing_key:
116
179
  specification_version: 4
117
- summary: Simple Ruby DSL to generate use cases restricted by sets of rules
180
+ summary: Simple tool to generate use cases restricted by sets of rules
118
181
  test_files:
119
- - test/agents/console_output_test.rb
120
- - test/agents/sets.test.rb
121
- - test/agents_test.rb
122
- - test/casegen.tests.rb
123
- - test/parser_test.rb
124
- - test/test_helper.rb
182
+ - spec/cart_sample_spec.rb
183
+ - spec/case_gen/combination_spec.rb
184
+ - spec/case_gen/exclude_rule_spec.rb
185
+ - spec/exclude_as_table_spec.rb
186
+ - spec/exclude_as_text_spec.rb
187
+ - spec/exclude_inline_footnotes_spec.rb
188
+ - spec/exclude_inline_spec.rb
189
+ - spec/expect_only_spec.rb
190
+ - spec/spec_helper.rb
data/.idea/encodings.xml DELETED
@@ -1,5 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
4
- </project>
5
-
data/.idea/misc.xml DELETED
@@ -1,5 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectRootManager" version="2" project-jdk-name="ruby-1.9.2-p180" project-jdk-type="RUBY_SDK" />
4
- </project>
5
-
data/.idea/modules.xml DELETED
@@ -1,9 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/casegen.iml" filepath="$PROJECT_DIR$/.idea/casegen.iml" />
6
- </modules>
7
- </component>
8
- </project>
9
-
data/.idea/vcs.xml DELETED
@@ -1,7 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
- </component>
6
- </project>
7
-
data/doc/calc.sample.txt DELETED
@@ -1,13 +0,0 @@
1
- sets
2
- ----
3
- first number: 0, 1
4
- operator: +, -, *, /
5
- second number: 0, 1
6
-
7
- rules(sets)
8
- -----------
9
- exclude operator = / AND second number = 0
10
- Divide by zero error
11
-
12
- console(rules)
13
- --------------
data/doc/cart.sample.rb DELETED
@@ -1,3 +0,0 @@
1
- require_relative '../lib/casegen'
2
-
3
- CLabs::CaseGen::CaseGen.new(File.read(File.join(__dir__, 'cart.sample.txt')))
data/doc/cart.sample.txt DELETED
@@ -1,33 +0,0 @@
1
- sets
2
- ------------
3
- payment: Credit, Check, Online Bank
4
- amount: 100, 1,000, 10,000
5
- shipping: Ground, Air
6
- ship to country: US, Outside US
7
- bill to country: US, Outside US
8
-
9
-
10
- rules(sets)
11
- ---------------------------
12
- # Comments supported
13
- exclude shipping = Ground AND ship to country = Outside US
14
- Our ground shipper will only ship things within the US.
15
-
16
- # Single or double equals sign supported - they're synonymous
17
- exclude payment = Check AND bill to country == Outside US
18
- Our bank will not accept checks written from banks outside the US.
19
-
20
- #[Complex booleans not supported yet]
21
- #exclude payment = Online Bank AND (amount == 1,000 OR amount = 10,000)
22
- exclude payment = Online Bank AND amount == 1,000
23
- exclude payment = Online Bank AND amount == 10,000
24
- While the online bank will process amounts > $1,000, we've experienced
25
- occasional problems with their services and have had to write off some
26
- transactions, so we no longer allow this payment option for amounts greater
27
- than $1,000
28
-
29
- exclude ship to country = US AND bill to country = Outside US
30
- If we're shipping to the US, billing party cannot be outside US
31
-
32
- console(rules)
33
- ----------