quixote 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f193d97df3faf9ca2ff91ce7c93b07e802a29e0
4
+ data.tar.gz: 3410d685a2fe5cd3062a673d15904f25abc7661d
5
+ SHA512:
6
+ metadata.gz: 582a2e1b9116635f9a8c1fdc65d2b63ef8c1600f944f0bfe6c4bc0e478e95578a08a437048c4d5fec984caf2fe915942cbe28a5eaa3220900a8966d973c8e30f
7
+ data.tar.gz: 62451bf971f9fd55831067ed6dd494a2407f812e82f2b9c4a6d97f92f7fdebf83443614e372223d26de8052d69b09afea3b0782e3b880ee4a34d5a8db92cb523
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  *.gem
2
2
  .bundle
3
3
  Gemfile.lock
4
+ .ruby-version
4
5
  pkg/*
5
6
  .rvmrc
6
7
  .DS_Store
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.1.2
@@ -0,0 +1,8 @@
1
+ ## Changelog
2
+
3
+ ### Version 0.2.0
4
+ * Add support for floats
5
+ * Add support for lambdas for custom progressions
6
+
7
+ ### Version 0.1.0
8
+ * Initial release
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in quixote.gemspec
3
+ gem 'pry'
4
+ gem 'rake'
5
+
4
6
  gemspec
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  Quixote
2
2
  =======
3
3
 
4
- A simple tool for statefully generating time-series data.
4
+ [![Gem Version](https://badge.fury.io/rb/quixote.svg)](http://badge.fury.io/rb/quixote) [![Build Status](https://travis-ci.org/nextmat/quixote.svg?branch=master)](https://travis-ci.org/nextmat/quixote)
5
+
6
+ A simple tool for statefully generating time-series data. Requires Ruby 1.9 or greater.
5
7
 
6
8
  ## Installation
7
9
 
@@ -17,34 +19,44 @@ Then, in your application or script:
17
19
 
18
20
  For each data stream you want to generate, set up a `Quixote` object. Here are some examples:
19
21
 
20
- percentage = Quixote.new(:min => 0, :max => 100, :range_by => 10)
21
- fahrenheit = Quixote.new(:min => -30.0, :max => 120.0, :range_by => 3.0)
22
-
22
+ percentage = Quixote.new(min: 0, max: 100, range_by: 10)
23
+ fahrenheit = Quixote.new(min: -30.0, max: 120.0, range_by: 3.0)
24
+
23
25
  If you don't specify any initialization options the object will be assumed to be a percentage and will default to the settings of the `percentage` object above.
24
-
26
+
25
27
  An initial value will be randomly generated and can be accessed with `#last`:
26
28
 
27
- percentage.last #=> 58
28
-
29
- If you want to enforce a certain starting value, just set last to whatever you want:
29
+ percentage.last #=> 58
30
30
 
31
- percentage.last = 60
31
+ If you want to enforce a certain starting value, you can provide that as well:
32
+
33
+ percentage = Quixote.new(start: 15, min: 0, max: 100, range_by: 10)
32
34
 
33
35
  By default each following value will range up or down by a random value up to a max of `range_by`. To get a series of stateful values just call `#next`:
34
36
 
35
37
  percentage.next #=> 64
36
38
  percentage.next #=> 66
37
- percentage.next #=> 58
38
-
39
- You can use `#last` to retrieve the most recently generated number or move the range to a number you select at any time.
40
-
39
+ percentage.next #=> 58
40
+
41
41
  This makes it trivial to generate stateful runs of any length you want:
42
42
 
43
43
  values = []
44
44
  100.times { values << percentage.next }
45
-
45
+
46
46
  values #=> [49, 55, 48, …]
47
47
 
48
+ You can use `#last` to retrieve the most recently generated number or move the range to a number you select at any time.
49
+
50
+ ## Custom Progressions
51
+
52
+ If you want more complex progression behavior you can provide your own lambda:
53
+
54
+ by_two = ->(last) { last + 2 }
55
+ incrementor = Quixote.new(start: 0, progress: by_two)
56
+
57
+ incrementor.last #=> 0
58
+ incrementor.next #=> 2
59
+ incrementor.next #=> 4
48
60
 
49
61
  ## Contribution
50
62
 
@@ -56,4 +68,4 @@ This makes it trivial to generate stateful runs of any length you want:
56
68
 
57
69
  ## Copyright
58
70
 
59
- Copyright (c) 2012 Matt Sanders. See LICENSE for details.
71
+ Copyright (c) 2012-2014 Matt Sanders. See LICENSE for details.
@@ -4,24 +4,28 @@ $:.unshift(File.dirname(__FILE__)) unless
4
4
  require "quixote/version"
5
5
 
6
6
  class Quixote
7
- attr_accessor :min, :max, :range_by, :last
7
+ attr_accessor :min, :max, :range_by, :last, :progress
8
8
 
9
9
  def initialize(options={})
10
+ start = options.delete(:start)
11
+
10
12
  defaults = {
11
- :max => 100,
12
- :min => 0,
13
- :range_by => 10
13
+ max: 100,
14
+ min: 0,
15
+ range_by: 10
14
16
  }
15
17
 
16
18
  defaults.merge(options).each do |key, value|
17
19
  send("#{key}=", value)
18
20
  end
19
21
 
20
- @last = random_start_point
22
+ @last = start || random_start_point
21
23
  end
22
24
 
23
25
  def next
24
- if last == max
26
+ if progress
27
+ run_custom
28
+ elsif last == max
25
29
  decrement
26
30
  elsif last == min || (rand < 0.5)
27
31
  increment
@@ -34,16 +38,24 @@ class Quixote
34
38
  private
35
39
 
36
40
  def increment
37
- @last += rand(range_by+1)
41
+ @last += interval
38
42
  @last = max if last > max
39
43
  end
40
44
 
41
45
  def decrement
42
- @last -= rand(range_by+1)
46
+ @last -= interval
43
47
  @last = min if last < min
44
48
  end
45
-
49
+
50
+ def interval
51
+ rand(0..range_by)
52
+ end
53
+
46
54
  def random_start_point
47
- rand((max-min)+1) + min
55
+ rand(min..max)
56
+ end
57
+
58
+ def run_custom
59
+ @last = progress.call(@last)
48
60
  end
49
61
  end
@@ -1,3 +1,3 @@
1
1
  class Quixote
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
12
12
  s.summary = %q{Simple stateful generator for time-series data}
13
13
  s.description = %q{A flexible, stateful generator for sample time-series data}
14
14
 
15
- #s.rubyforge_project = "quixote"
16
-
15
+ s.required_ruby_version = '>= 1.9.0'
16
+
17
17
  s.rdoc_options = ["--charset=UTF-8"]
18
18
  s.extra_rdoc_files = %w[LICENSE]
19
19
 
@@ -1,5 +1,3 @@
1
- puts "running"
2
-
3
1
  require "helper"
4
2
 
5
3
  class TextQuixote < MiniTest::Spec
@@ -10,36 +8,41 @@ class TextQuixote < MiniTest::Spec
10
8
  assert_equal 0, q.min
11
9
  assert_equal 10, q.range_by
12
10
  end
13
-
11
+
14
12
  def test_initialization
15
- q = Quixote.new(:min => 50, :max => 200, :range_by => 80)
13
+ q = Quixote.new(min: 50, max: 200, range_by: 80)
16
14
  assert_equal 50, q.min
17
15
  assert_equal 200, q.max
18
16
  assert_equal 80, q.range_by
19
17
  end
20
-
21
- def test_starting_point
18
+
19
+ def test_set_starting_point
20
+ q = Quixote.new(start: 55)
21
+ assert_equal 55, q.last
22
+ end
23
+
24
+ def test_random_starting_point
22
25
  100.times do
23
- q = Quixote.new(:max => 20, :min => 10)
26
+ q = Quixote.new(max: 20, min: 10)
24
27
  assert q.last >= 10, "#{q.last} is < min (10)"
25
28
  assert q.last <= 20, "#{q.last} is > max (20)"
26
29
  end
27
-
30
+
28
31
  q = Quixote.new
29
32
  q.last = 25
30
33
  assert_equal 25, q.last, 'last should be settable'
31
34
  end
32
-
35
+
33
36
  def test_range_limits
34
- q = Quixote.new(:min => 1, :max => 10, :range_by => 4)
37
+ q = Quixote.new(min: 1, max: 10, range_by: 4)
35
38
  values = []
36
39
  1000.times { values << q.next } # build up a bunch of values
37
40
  assert values.min >= 1, 'should never range below min'
38
41
  assert values.max <= 10, 'should never range above max'
39
42
  end
40
-
43
+
41
44
  def test_range_size
42
- q = Quixote.new(:min => 1, :max => 20, :range_by => 6)
45
+ q = Quixote.new(min: 1, max: 20, range_by: 6)
43
46
  last = q.last
44
47
  deltas = []
45
48
  1000.times do
@@ -50,4 +53,38 @@ class TextQuixote < MiniTest::Spec
50
53
  assert_equal 0, deltas.min
51
54
  end
52
55
 
56
+ def test_floats
57
+ q = Quixote.new(min: 1.0, max: 100.0, range_by: 10.0)
58
+ values = []
59
+ 1000.times do
60
+ last = q.last
61
+ latest = q.next
62
+ # puts "last: #{last}, latest: #{latest}, delta: #{latest-last}"
63
+ refute_equal last, latest
64
+ assert_in_delta last, latest, 10.0
65
+ end
66
+ end
67
+
68
+ def test_increment_lambda
69
+ by_two = ->(last) { last + 2 }
70
+ q = Quixote.new(start: 0, progress: by_two)
71
+
72
+ assert_equal 2, q.next
73
+ assert_equal 4, q.next
74
+ end
75
+
76
+ def test_alternating_lambda
77
+ alternate = lambda do |last|
78
+ @runs ||= 0
79
+ @runs += 1
80
+ if (@runs % 2) == 0 then 0 else 5 end
81
+ end
82
+ q = Quixote.new(start: 0, progress: alternate)
83
+
84
+ assert_equal 5, q.next
85
+ assert_equal 0, q.next
86
+ assert_equal 5, q.next
87
+ assert_equal 0, q.next
88
+ end
89
+
53
90
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quixote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Matt Sanders
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-06-15 00:00:00.000000000 Z
11
+ date: 2014-09-09 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: A flexible, stateful generator for sample time-series data
15
14
  email:
@@ -19,7 +18,9 @@ extensions: []
19
18
  extra_rdoc_files:
20
19
  - LICENSE
21
20
  files:
22
- - .gitignore
21
+ - ".gitignore"
22
+ - ".travis.yml"
23
+ - CHANGELOG.md
23
24
  - Gemfile
24
25
  - LICENSE
25
26
  - README.md
@@ -31,30 +32,28 @@ files:
31
32
  - test/test_quixote.rb
32
33
  homepage: https://github.com/nextmat/quixote
33
34
  licenses: []
35
+ metadata: {}
34
36
  post_install_message:
35
37
  rdoc_options:
36
- - --charset=UTF-8
38
+ - "--charset=UTF-8"
37
39
  require_paths:
38
40
  - lib
39
41
  required_ruby_version: !ruby/object:Gem::Requirement
40
- none: false
41
42
  requirements:
42
- - - ! '>='
43
+ - - ">="
43
44
  - !ruby/object:Gem::Version
44
- version: '0'
45
+ version: 1.9.0
45
46
  required_rubygems_version: !ruby/object:Gem::Requirement
46
- none: false
47
47
  requirements:
48
- - - ! '>='
48
+ - - ">="
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  requirements: []
52
52
  rubyforge_project:
53
- rubygems_version: 1.8.16
53
+ rubygems_version: 2.2.2
54
54
  signing_key:
55
- specification_version: 3
55
+ specification_version: 4
56
56
  summary: Simple stateful generator for time-series data
57
57
  test_files:
58
58
  - test/helper.rb
59
59
  - test/test_quixote.rb
60
- has_rdoc: