test_data_generator_with_constraints 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 18e6d06996559fca82b6db8a47f63108250f036c
4
+ data.tar.gz: a97232465f4029246c12a9a0d6b2731247efe139
5
+ SHA512:
6
+ metadata.gz: 4945f7ce1f1e0d7eb5b00d14318f6d0b70c3502161398e44ce3d17c92764f66fd919eb87fbbf63ead954fe5caa39a7a6bc0b90bd58a8d3373dd7e9a464f9e1a2
7
+ data.tar.gz: 982c9440107f7877ba5b4431530221869ee176c8294499b77c801d7592897a475acbb7344463e897af87b6d1928193f540dd668bb91c7e1b96803be0d03c82c5
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format nested
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.8.0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0"
12
+ gem "jeweler", "~> 2.0.1"
13
+ gem "simplecov", ">= 0"
14
+ gem "pairwise", "~> 0.2.1"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,74 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.5)
5
+ builder (3.2.2)
6
+ descendants_tracker (0.0.3)
7
+ diff-lcs (1.1.3)
8
+ docile (1.1.3)
9
+ faraday (0.9.0)
10
+ multipart-post (>= 1.2, < 3)
11
+ git (1.2.6)
12
+ github_api (0.11.2)
13
+ addressable (~> 2.3)
14
+ descendants_tracker (~> 0.0.1)
15
+ faraday (~> 0.8, < 0.10)
16
+ hashie (>= 1.2)
17
+ multi_json (>= 1.7.5, < 2.0)
18
+ nokogiri (~> 1.6.0)
19
+ oauth2
20
+ hashie (2.0.5)
21
+ highline (1.6.20)
22
+ jeweler (2.0.1)
23
+ builder
24
+ bundler (>= 1.0)
25
+ git (>= 1.2.5)
26
+ github_api
27
+ highline (>= 1.6.15)
28
+ nokogiri (>= 1.5.10)
29
+ rake
30
+ rdoc
31
+ json (1.8.1)
32
+ jwt (0.1.11)
33
+ multi_json (>= 1.5)
34
+ mini_portile (0.5.2)
35
+ multi_json (1.9.0)
36
+ multi_xml (0.5.5)
37
+ multipart-post (2.0.0)
38
+ nokogiri (1.6.1)
39
+ mini_portile (~> 0.5.0)
40
+ oauth2 (0.9.3)
41
+ faraday (>= 0.8, < 0.10)
42
+ jwt (~> 0.1.8)
43
+ multi_json (~> 1.3)
44
+ multi_xml (~> 0.5)
45
+ rack (~> 1.2)
46
+ pairwise (0.2.1)
47
+ rack (1.5.2)
48
+ rake (10.1.1)
49
+ rdoc (3.12.2)
50
+ json (~> 1.4)
51
+ rspec (2.8.0)
52
+ rspec-core (~> 2.8.0)
53
+ rspec-expectations (~> 2.8.0)
54
+ rspec-mocks (~> 2.8.0)
55
+ rspec-core (2.8.0)
56
+ rspec-expectations (2.8.0)
57
+ diff-lcs (~> 1.1.2)
58
+ rspec-mocks (2.8.0)
59
+ simplecov (0.8.2)
60
+ docile (~> 1.1.0)
61
+ multi_json
62
+ simplecov-html (~> 0.8.0)
63
+ simplecov-html (0.8.0)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ bundler (~> 1.0)
70
+ jeweler (~> 2.0.1)
71
+ pairwise (~> 0.2.1)
72
+ rdoc (~> 3.12)
73
+ rspec (~> 2.8.0)
74
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 jatla
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,108 @@
1
+ = test_data_generator_with_constraints
2
+
3
+ Among the various techniques to generate test data, combinatorial test generation using all-pairs(pairwise) methodology is one. This gem is an effort to apply pairwise methodology to hierarchical data models. Further goal is to have the ability to specify constraints and restrict the test data generated based on those constraints.
4
+
5
+ Some references to pairwise testing literature if you want to know more:
6
+
7
+ * http://www.pairwise.org
8
+ * http://www.developsense.com/pairwiseTesting.html
9
+ * http://aetgweb.argreenhouse.com/papers.shtml
10
+
11
+ === Usage
12
+
13
+ * Installing gem
14
+
15
+ $ gem install test_data_generator_with_constraints
16
+
17
+ * Create a model file
18
+
19
+ $ vi model.rb
20
+
21
+ complexConstraint = lambda {|t| t if ((t[:inner4] != t[:inner5]) && (t[:innermost2] != t[:innermost3]) && (t[:innermost1] > 3))}
22
+ $dataModel =
23
+ {
24
+ model:
25
+ {
26
+ outer1:
27
+ {
28
+ inner1:
29
+ {
30
+ innermost1: (1..5),
31
+ innermost2: [true, false],
32
+ innermost3: [true, false]
33
+ },
34
+ inner2: [1,-1]
35
+ },
36
+ outer2:
37
+ {
38
+ inner3: (1..3),
39
+ inner4: [true, false],
40
+ inner5: [true, false]
41
+ }
42
+ },
43
+ constraints:
44
+ {
45
+ model: [complexConstraint]
46
+ }
47
+ }
48
+
49
+ * Running the tool
50
+ Usage: test_data_generator_with_constraints.rb [options]
51
+ -m, --modelFilePath filePath Path to file containing model and constaints. This is a required parameter.
52
+ -o, --outputFilePath filePath Output file where generated test data set is written to. If not provided test data set would be generated to temp.txt
53
+ -h, --help Display this screen
54
+
55
+ Example: test_data_generator_with_constraints.rb -m model.rb -o testData.txt
56
+
57
+ * Sample output
58
+
59
+ GENERATED TEST DATA:
60
+
61
+ 1. {:innermost1=>4, :innermost2=>true, :innermost3=>false, :inner2=>1, :inner3=>2, :inner4=>true, :inner5=>false}
62
+ 2. {:innermost1=>4, :innermost2=>true, :innermost3=>false, :inner2=>1, :inner3=>2, :inner4=>false, :inner5=>true}
63
+ 3. {:innermost1=>4, :innermost2=>true, :innermost3=>false, :inner2=>1, :inner3=>3, :inner4=>true, :inner5=>false}
64
+ 4. {:innermost1=>4, :innermost2=>true, :innermost3=>false, :inner2=>1, :inner3=>3, :inner4=>false, :inner5=>true}
65
+ 5. {:innermost1=>4, :innermost2=>true, :innermost3=>false, :inner2=>-1, :inner3=>2, :inner4=>true, :inner5=>false}
66
+ 6. {:innermost1=>4, :innermost2=>true, :innermost3=>false, :inner2=>-1, :inner3=>2, :inner4=>false, :inner5=>true}
67
+ 7. {:innermost1=>4, :innermost2=>true, :innermost3=>false, :inner2=>-1, :inner3=>3, :inner4=>true, :inner5=>false}
68
+ 8. {:innermost1=>4, :innermost2=>true, :innermost3=>false, :inner2=>-1, :inner3=>3, :inner4=>false, :inner5=>true}
69
+ 9. {:innermost1=>4, :innermost2=>false, :innermost3=>true, :inner2=>1, :inner3=>2, :inner4=>true, :inner5=>false}
70
+ 10. {:innermost1=>4, :innermost2=>false, :innermost3=>true, :inner2=>1, :inner3=>2, :inner4=>false, :inner5=>true}
71
+ 11. {:innermost1=>4, :innermost2=>false, :innermost3=>true, :inner2=>1, :inner3=>3, :inner4=>true, :inner5=>false}
72
+ 12. {:innermost1=>4, :innermost2=>false, :innermost3=>true, :inner2=>1, :inner3=>3, :inner4=>false, :inner5=>true}
73
+ 13. {:innermost1=>4, :innermost2=>false, :innermost3=>true, :inner2=>-1, :inner3=>2, :inner4=>true, :inner5=>false}
74
+ 14. {:innermost1=>4, :innermost2=>false, :innermost3=>true, :inner2=>-1, :inner3=>2, :inner4=>false, :inner5=>true}
75
+ 15. {:innermost1=>4, :innermost2=>false, :innermost3=>true, :inner2=>-1, :inner3=>3, :inner4=>true, :inner5=>false}
76
+ 16. {:innermost1=>4, :innermost2=>false, :innermost3=>true, :inner2=>-1, :inner3=>3, :inner4=>false, :inner5=>true}
77
+ 17. {:innermost1=>5, :innermost2=>true, :innermost3=>false, :inner2=>1, :inner3=>2, :inner4=>true, :inner5=>false}
78
+ 18. {:innermost1=>5, :innermost2=>true, :innermost3=>false, :inner2=>1, :inner3=>2, :inner4=>false, :inner5=>true}
79
+ 19. {:innermost1=>5, :innermost2=>true, :innermost3=>false, :inner2=>1, :inner3=>3, :inner4=>true, :inner5=>false}
80
+ 20. {:innermost1=>5, :innermost2=>true, :innermost3=>false, :inner2=>1, :inner3=>3, :inner4=>false, :inner5=>true}
81
+ 21. {:innermost1=>5, :innermost2=>true, :innermost3=>false, :inner2=>-1, :inner3=>2, :inner4=>true, :inner5=>false}
82
+ 22. {:innermost1=>5, :innermost2=>true, :innermost3=>false, :inner2=>-1, :inner3=>2, :inner4=>false, :inner5=>true}
83
+ 23. {:innermost1=>5, :innermost2=>true, :innermost3=>false, :inner2=>-1, :inner3=>3, :inner4=>true, :inner5=>false}
84
+ 24. {:innermost1=>5, :innermost2=>true, :innermost3=>false, :inner2=>-1, :inner3=>3, :inner4=>false, :inner5=>true}
85
+ 25. {:innermost1=>5, :innermost2=>false, :innermost3=>true, :inner2=>1, :inner3=>2, :inner4=>true, :inner5=>false}
86
+ 26. {:innermost1=>5, :innermost2=>false, :innermost3=>true, :inner2=>1, :inner3=>2, :inner4=>false, :inner5=>true}
87
+ 27. {:innermost1=>5, :innermost2=>false, :innermost3=>true, :inner2=>1, :inner3=>3, :inner4=>true, :inner5=>false}
88
+ 28. {:innermost1=>5, :innermost2=>false, :innermost3=>true, :inner2=>1, :inner3=>3, :inner4=>false, :inner5=>true}
89
+ 29. {:innermost1=>5, :innermost2=>false, :innermost3=>true, :inner2=>-1, :inner3=>2, :inner4=>true, :inner5=>false}
90
+ 30. {:innermost1=>5, :innermost2=>false, :innermost3=>true, :inner2=>-1, :inner3=>2, :inner4=>false, :inner5=>true}
91
+ 31. {:innermost1=>5, :innermost2=>false, :innermost3=>true, :inner2=>-1, :inner3=>3, :inner4=>true, :inner5=>false}
92
+ 32. {:innermost1=>5, :innermost2=>false, :innermost3=>true, :inner2=>-1, :inner3=>3, :inner4=>false, :inner5=>true}
93
+
94
+ == Contributing to test_data_generator_with_constraints
95
+
96
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
97
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
98
+ * Fork the project.
99
+ * Start a feature/bugfix branch.
100
+ * Commit and push until you are happy with your contribution.
101
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
102
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
103
+
104
+ == Copyright
105
+
106
+ Copyright (c) 2014 jatla. See LICENSE.txt for
107
+ further details.
108
+
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "test_data_generator_with_constraints"
18
+ gem.homepage = "http://github.com/jatla/test_data_generator_with_constraints"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Test data generator for hierarchical modelsusing allpairs methodology}
21
+ gem.description = %Q{Given a model as ruby hash and constraints as ruby procs, test data is generated based on allpairs methodology and constraints applied to prune the data set}
22
+ gem.email = "jayaprakash.atla@gmail.com"
23
+ gem.authors = ["jatla"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ desc "Code coverage detail"
35
+ task :simplecov do
36
+ ENV['COVERAGE'] = "true"
37
+ Rake::Task['spec'].execute
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rdoc/task'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "test_data_generator_with_constraints #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ rdoc.options << "--all"
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/test_data_generator_with_constraints')
3
+ require 'optparse'
4
+
5
+ options = {:m => nil, :o => nil}
6
+
7
+ parser = OptionParser.new do |opts|
8
+
9
+ opts.banner = "Usage: test_data_generator_with_constraints.rb [options] "
10
+
11
+ opts.on('-m filePath', '--modelFilePath filePath', 'Path to file containing model and constaints. This is a required parameter.') do |filePath|
12
+ options[:m] = filePath
13
+ end
14
+
15
+ opts.on('-o filePath', '--outputFilePath filePath', 'Output file where generated test data set is written to. If not provided test data set would be generated to temp.txt') do |filePath|
16
+ options[:o] = filePath
17
+ end
18
+
19
+ opts.on( '-h', '--help', 'Display this screen' ) do
20
+ puts opts
21
+ exit
22
+ end
23
+ end
24
+
25
+ parser.parse!
26
+
27
+ outputFile = (options[:o].eql? nil) ? "temp.txt" : "#{options[:o]}"
28
+ if options[:m] != nil
29
+ load "#{options[:m]}"
30
+ else
31
+ puts "Not a valid option. See help!"
32
+ end
33
+
34
+ TestDataGeneratorWithConstraints.instance.generate $dataModel, outputFile
@@ -0,0 +1,27 @@
1
+ complexConstraint = lambda {|t| t if ((t[:inner4] != t[:inner5]) && (t[:innermost2] != t[:innermost3]) && (t[:innermost1] > 3))}
2
+ $dataModel =
3
+ {
4
+ model:
5
+ {
6
+ outer1:
7
+ {
8
+ inner1:
9
+ {
10
+ innermost1: (1..5),
11
+ innermost2: [true, false],
12
+ innermost3: [true, false]
13
+ },
14
+ inner2: [1,-1]
15
+ },
16
+ outer2:
17
+ {
18
+ inner3: (1..3),
19
+ inner4: [true, false],
20
+ inner5: [true, false]
21
+ }
22
+ },
23
+ constraints:
24
+ {
25
+ model: [complexConstraint]
26
+ }
27
+ }
@@ -0,0 +1,48 @@
1
+ MODEL:
2
+
3
+ {:outer1=>
4
+ {:inner1=>
5
+ {:innermost1=>1..5,
6
+ :innermost2=>[true, false],
7
+ :innermost3=>[true, false]},
8
+ :inner2=>[1, -1]},
9
+ :outer2=>{:inner3=>1..3, :inner4=>[true, false], :inner5=>[true, false]}}
10
+
11
+ ------------------------
12
+
13
+ GENERATED TEST DATA:
14
+
15
+ 1. {:innermost1=>4, :innermost2=>true, :innermost3=>false, :inner2=>1, :inner3=>2, :inner4=>true, :inner5=>false}
16
+ 2. {:innermost1=>4, :innermost2=>true, :innermost3=>false, :inner2=>1, :inner3=>2, :inner4=>false, :inner5=>true}
17
+ 3. {:innermost1=>4, :innermost2=>true, :innermost3=>false, :inner2=>1, :inner3=>3, :inner4=>true, :inner5=>false}
18
+ 4. {:innermost1=>4, :innermost2=>true, :innermost3=>false, :inner2=>1, :inner3=>3, :inner4=>false, :inner5=>true}
19
+ 5. {:innermost1=>4, :innermost2=>true, :innermost3=>false, :inner2=>-1, :inner3=>2, :inner4=>true, :inner5=>false}
20
+ 6. {:innermost1=>4, :innermost2=>true, :innermost3=>false, :inner2=>-1, :inner3=>2, :inner4=>false, :inner5=>true}
21
+ 7. {:innermost1=>4, :innermost2=>true, :innermost3=>false, :inner2=>-1, :inner3=>3, :inner4=>true, :inner5=>false}
22
+ 8. {:innermost1=>4, :innermost2=>true, :innermost3=>false, :inner2=>-1, :inner3=>3, :inner4=>false, :inner5=>true}
23
+ 9. {:innermost1=>4, :innermost2=>false, :innermost3=>true, :inner2=>1, :inner3=>2, :inner4=>true, :inner5=>false}
24
+ 10. {:innermost1=>4, :innermost2=>false, :innermost3=>true, :inner2=>1, :inner3=>2, :inner4=>false, :inner5=>true}
25
+ 11. {:innermost1=>4, :innermost2=>false, :innermost3=>true, :inner2=>1, :inner3=>3, :inner4=>true, :inner5=>false}
26
+ 12. {:innermost1=>4, :innermost2=>false, :innermost3=>true, :inner2=>1, :inner3=>3, :inner4=>false, :inner5=>true}
27
+ 13. {:innermost1=>4, :innermost2=>false, :innermost3=>true, :inner2=>-1, :inner3=>2, :inner4=>true, :inner5=>false}
28
+ 14. {:innermost1=>4, :innermost2=>false, :innermost3=>true, :inner2=>-1, :inner3=>2, :inner4=>false, :inner5=>true}
29
+ 15. {:innermost1=>4, :innermost2=>false, :innermost3=>true, :inner2=>-1, :inner3=>3, :inner4=>true, :inner5=>false}
30
+ 16. {:innermost1=>4, :innermost2=>false, :innermost3=>true, :inner2=>-1, :inner3=>3, :inner4=>false, :inner5=>true}
31
+ 17. {:innermost1=>5, :innermost2=>true, :innermost3=>false, :inner2=>1, :inner3=>2, :inner4=>true, :inner5=>false}
32
+ 18. {:innermost1=>5, :innermost2=>true, :innermost3=>false, :inner2=>1, :inner3=>2, :inner4=>false, :inner5=>true}
33
+ 19. {:innermost1=>5, :innermost2=>true, :innermost3=>false, :inner2=>1, :inner3=>3, :inner4=>true, :inner5=>false}
34
+ 20. {:innermost1=>5, :innermost2=>true, :innermost3=>false, :inner2=>1, :inner3=>3, :inner4=>false, :inner5=>true}
35
+ 21. {:innermost1=>5, :innermost2=>true, :innermost3=>false, :inner2=>-1, :inner3=>2, :inner4=>true, :inner5=>false}
36
+ 22. {:innermost1=>5, :innermost2=>true, :innermost3=>false, :inner2=>-1, :inner3=>2, :inner4=>false, :inner5=>true}
37
+ 23. {:innermost1=>5, :innermost2=>true, :innermost3=>false, :inner2=>-1, :inner3=>3, :inner4=>true, :inner5=>false}
38
+ 24. {:innermost1=>5, :innermost2=>true, :innermost3=>false, :inner2=>-1, :inner3=>3, :inner4=>false, :inner5=>true}
39
+ 25. {:innermost1=>5, :innermost2=>false, :innermost3=>true, :inner2=>1, :inner3=>2, :inner4=>true, :inner5=>false}
40
+ 26. {:innermost1=>5, :innermost2=>false, :innermost3=>true, :inner2=>1, :inner3=>2, :inner4=>false, :inner5=>true}
41
+ 27. {:innermost1=>5, :innermost2=>false, :innermost3=>true, :inner2=>1, :inner3=>3, :inner4=>true, :inner5=>false}
42
+ 28. {:innermost1=>5, :innermost2=>false, :innermost3=>true, :inner2=>1, :inner3=>3, :inner4=>false, :inner5=>true}
43
+ 29. {:innermost1=>5, :innermost2=>false, :innermost3=>true, :inner2=>-1, :inner3=>2, :inner4=>true, :inner5=>false}
44
+ 30. {:innermost1=>5, :innermost2=>false, :innermost3=>true, :inner2=>-1, :inner3=>2, :inner4=>false, :inner5=>true}
45
+ 31. {:innermost1=>5, :innermost2=>false, :innermost3=>true, :inner2=>-1, :inner3=>3, :inner4=>true, :inner5=>false}
46
+ 32. {:innermost1=>5, :innermost2=>false, :innermost3=>true, :inner2=>-1, :inner3=>3, :inner4=>false, :inner5=>true}
47
+ ------------------------
48
+
@@ -0,0 +1,165 @@
1
+ require 'singleton'
2
+ require 'pairwise'
3
+ require 'pp'
4
+
5
+ # Top level class used by cbtdg.rb commandline tool to traverse through
6
+ # hierarchical data models and generate test data using pairwise methodology.
7
+
8
+ class TestDataGeneratorWithConstraints
9
+ include Singleton
10
+ include Pairwise
11
+
12
+ # Top level method to generate test data and write it to the specified output file.
13
+ #
14
+ # ==== Attributes
15
+ #
16
+ # * +dataModel+ - The dataModel(which is a Hash) for which test data has to be generated.
17
+ # * +outPutFilePath+ - Path of the file to which generated test data needs to be written to.
18
+
19
+ def generate(dataModelWithConstraints, outPutFilePath=nil)
20
+ @dataModel = Marshal.load(Marshal.dump(dataModelWithConstraints[:model]))
21
+ @constraints = dataModelWithConstraints[:constraints]
22
+ testTuples = generateTestDataForModel(@dataModel)
23
+ if !outPutFilePath.nil?
24
+ outputFile = File.open(outPutFilePath, "w")
25
+ begin
26
+ writeToFile(outputFile, dataModelWithConstraints[:model], testTuples)
27
+ rescue IOError => e
28
+ puts e
29
+ ensure
30
+ outputFile.close unless outputFile.nil?
31
+ end
32
+ end
33
+ testTuples
34
+ end
35
+
36
+ # Method to generate test data for a given model using pairwise methodology
37
+ #
38
+ # ==== Attributes
39
+ #
40
+ # * +dataModel+ - The dataModel(which is a Hash) for which test data has to be generated.
41
+
42
+ def generateTestDataForModel(dataModel)
43
+ @pairWiseData = {}
44
+ generatePairWiseData(:model, dataModel)
45
+ testTuples = []
46
+ @pairWiseData[:model].each do |p|
47
+ testTuples << convertArrayToHash(p)
48
+ end
49
+ testTuples
50
+ end
51
+
52
+ private
53
+
54
+ # Helper method that generates pairwise data for each sub-structure in the model.
55
+ #
56
+ # ==== Attributes
57
+ #
58
+ # * +key+ - The key of the sub-structure in original model.
59
+ # * +data+ - Value for the above key in original model.
60
+
61
+ def generatePairWiseData(key, data)
62
+ if data.kind_of? Hash
63
+ data.each do |k, v|
64
+ data[k] = generatePairWiseData(k,v)
65
+ end
66
+ testData = data.values.length > 1 ? combinations(data.values) : data.values[0]
67
+ @pairWiseData[key] = applyConstraints(key, testData)
68
+ elsif (data.is_a? Array) && (data[0].is_a? Regexp)
69
+ length = data[1].nil? ? 1 : data[1]
70
+ count = data[2].nil? ? 10 : data[2]
71
+ else
72
+ data.to_a.collect{|a| [key,a]}
73
+ end
74
+ end
75
+
76
+ # Helper method that applies constraints for each sub-structure.
77
+ #
78
+ # ==== Attributes
79
+ #
80
+ # * +key+ - Key of the sub-structure whose constraints are to be applied.
81
+ # * +testData+ - Generated test data for the sub-structure.
82
+
83
+ def applyConstraints(key, data)
84
+ if (!@constraints.nil? && !@constraints[key].nil?)
85
+ @constraints[key].each do |c|
86
+ data.collect!{|d| c.call(convertArrayToHash(d))}.compact!
87
+ end
88
+ end
89
+ data
90
+ end
91
+
92
+ # Helper method that writes generated pairwise data to given file.
93
+ #
94
+ # ==== Attributes
95
+ #
96
+ # * +outPutFilePath+ - Path of the file to which generated test data needs to be written to.
97
+ # * +dataModel+ - Original data model for which test data is generated.
98
+ # * +testTuples+ - Test data generated for the given model.
99
+
100
+ def writeToFile(outputFile, dataModel, testTuples)
101
+ outputFile.write("MODEL:\n\n")
102
+ PP.pp(dataModel, outputFile)
103
+ #outputFile.write(dataModel.to_s)
104
+ outputFile.write("\n------------------------\n\n")
105
+ outputFile.write("GENERATED TEST DATA:\n\n")
106
+ testTuples.each_index do |i|
107
+ outputFile.write("#{i+1}. #{testTuples[i].to_s}\n")
108
+ end
109
+ outputFile.write("------------------------\n\n")
110
+
111
+ # outputFile.write("INTERMEDIATE DATA:\n\n")
112
+
113
+ # @pairWiseData.each do |k, v|
114
+ # outputFile.write("#{k} : \n")
115
+ # PP.pp(v, outputFile)
116
+ # outputFile.write("\n")
117
+ # #outputFile.write("#{k} : \n #{v.to_s}\n")
118
+ # end
119
+ # outputFile.write("------------------------\n\n")
120
+ end
121
+
122
+ # This is copied from the pairwise gem as the array of arrays
123
+ # generated from the model were being wrapped into another top level array by
124
+ # combinations method in Pairwise module.
125
+
126
+ def combinations(inputs)
127
+ raise InvalidInputData, "Minimum of 2 inputs are required to generate pairwise test set" unless valid?(inputs)
128
+ Pairwise::IPO.new(inputs).build
129
+ end
130
+
131
+ # This is copied from Pairwise module to support combinations method
132
+
133
+ def valid?(inputs)
134
+ array_of_arrays?(inputs) &&
135
+ inputs.length >= 2 &&
136
+ !inputs[0].empty? && !inputs[1].empty?
137
+ end
138
+
139
+ # This is copied from Pairwise module to support valid? method
140
+
141
+ def array_of_arrays?(data)
142
+ data.reject{|datum| datum.kind_of?(Array)}.empty?
143
+ end
144
+
145
+ def convertArrayToHash(array)
146
+ # The array should be converted using either
147
+ # Hash[p] or p.to_h. Need more work on this
148
+ hash = {}
149
+ array.flatten.each_slice(2) do |e|
150
+ hash[e[0]] = e[1]
151
+ end
152
+ hash
153
+ end
154
+
155
+ def generateRandomStringsFromRegEx regex, length, count
156
+ strings = []
157
+ loop do
158
+ string = (1..length).collect{rand(0..255).chr}.join
159
+ regex.match((1..length).collect{rand(0..255).chr}.join) {|m| strings << m.to_s if !m.nil?}
160
+ break if (strings.count != count)
161
+ #strings << string if string.match(regex)
162
+ end
163
+ strings
164
+ end
165
+ end
@@ -0,0 +1,29 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
18
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
19
+
20
+ require 'rspec'
21
+ require 'test_data_generator_with_constraints'
22
+
23
+ # Requires supporting files with custom matchers and macros, etc,
24
+ # in ./support/ and its subdirectories.
25
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
26
+
27
+ RSpec.configure do |config|
28
+
29
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "TestDataGeneratorWithConstraints" do
4
+ context "#generateTestDataForModel" do
5
+ it "successfully generates pairwise data for simple model" do
6
+
7
+ dataModel =
8
+ {
9
+ model:
10
+ {
11
+ supply: (0..3),
12
+ demand: (0..3)
13
+ },
14
+ constraints: {}
15
+ }
16
+ pairWiseData = TestDataGeneratorWithConstraints.instance.generateTestDataForModel(dataModel[:model])
17
+ pairWiseData.length.should eq 16
18
+ end
19
+ it "successfully generates pairwise data for simple models with constraints" do
20
+ constraint = lambda { |t| t if (t[:supply] >= t[:demand])}
21
+ dataModel =
22
+ {
23
+ model:
24
+ {
25
+ supply: (0..3),
26
+ demand: (0..3)
27
+ },
28
+ constraints:
29
+ {
30
+ model: [constraint]
31
+ }
32
+ }
33
+ pairWiseData = TestDataGeneratorWithConstraints.instance.generate(dataModel)
34
+ pairWiseData.length.should eq 10
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,71 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "test_data_generator_with_constraints"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["jatla"]
12
+ s.date = "2014-03-12"
13
+ s.description = "Given a model as ruby hash and constraints as ruby procs, test data is generated based on allpairs methodology and constraints applied to prune the data set"
14
+ s.email = "jayaprakash.atla@gmail.com"
15
+ s.executables = ["test_data_generator_with_constraints.rb"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ ".travis.yml",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE.txt",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "bin/test_data_generator_with_constraints.rb",
31
+ "examples/sample_model.rb",
32
+ "examples/sample_output.txt",
33
+ "lib/test_data_generator_with_constraints.rb",
34
+ "spec/spec_helper.rb",
35
+ "spec/test_data_generator_with_constraints_spec.rb",
36
+ "test_data_generator_with_constraints.gemspec"
37
+ ]
38
+ s.homepage = "http://github.com/jatla/test_data_generator_with_constraints"
39
+ s.licenses = ["MIT"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = "2.0.3"
42
+ s.summary = "Test data generator for hierarchical modelsusing allpairs methodology"
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 4
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
49
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
50
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
51
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
52
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
53
+ s.add_development_dependency(%q<pairwise>, ["~> 0.2.1"])
54
+ else
55
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
56
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
59
+ s.add_dependency(%q<simplecov>, [">= 0"])
60
+ s.add_dependency(%q<pairwise>, ["~> 0.2.1"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
64
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
65
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
66
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
67
+ s.add_dependency(%q<simplecov>, [">= 0"])
68
+ s.add_dependency(%q<pairwise>, ["~> 0.2.1"])
69
+ end
70
+ end
71
+
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: test_data_generator_with_constraints
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - jatla
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 2.8.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 2.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
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: pairwise
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 0.2.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 0.2.1
97
+ description: Given a model as ruby hash and constraints as ruby procs, test data is
98
+ generated based on allpairs methodology and constraints applied to prune the data
99
+ set
100
+ email: jayaprakash.atla@gmail.com
101
+ executables:
102
+ - test_data_generator_with_constraints.rb
103
+ extensions: []
104
+ extra_rdoc_files:
105
+ - LICENSE.txt
106
+ - README.rdoc
107
+ files:
108
+ - .document
109
+ - .rspec
110
+ - .travis.yml
111
+ - Gemfile
112
+ - Gemfile.lock
113
+ - LICENSE.txt
114
+ - README.rdoc
115
+ - Rakefile
116
+ - VERSION
117
+ - bin/test_data_generator_with_constraints.rb
118
+ - examples/sample_model.rb
119
+ - examples/sample_output.txt
120
+ - lib/test_data_generator_with_constraints.rb
121
+ - spec/spec_helper.rb
122
+ - spec/test_data_generator_with_constraints_spec.rb
123
+ - test_data_generator_with_constraints.gemspec
124
+ homepage: http://github.com/jatla/test_data_generator_with_constraints
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.0.3
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Test data generator for hierarchical modelsusing allpairs methodology
148
+ test_files: []