charosc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,72 @@
1
+ require "spec_helper"
2
+
3
+ module Charosc
4
+ describe Generator do
5
+ let(:generator) { described_class.new("This is a test.") }
6
+
7
+ describe "default settings" do
8
+ subject { generator }
9
+
10
+ its(:oscil) { should be_an(Oscillator) }
11
+ its(:depth) { should == 3 }
12
+ its(:mod_enabled) { should be_true }
13
+ its(:mod_inc) { should == 1 }
14
+ its(:mod_top) { should == 300 }
15
+ its(:mod_bottom) { should == 2 }
16
+
17
+ describe "Oscillator setup" do
18
+ subject { generator.oscil.options }
19
+
20
+ its([:top]) { should == 300 }
21
+ its([:bottom]) { should == 2 }
22
+ its([:inc]) { should == 1 }
23
+ end
24
+ end
25
+
26
+ describe "#generate" do
27
+ subject { generator }
28
+
29
+ it "returns a string of num_chars length" do
30
+ [100, 3000, 2].each do |n|
31
+ subject.generate(n).size.should == n
32
+ end
33
+ end
34
+
35
+ context "modulation enabled" do
36
+ before { subject.mod_enabled = true }
37
+
38
+ it "returns a string of num_chars length" do
39
+ [100, 3000, 2].each do |n|
40
+ subject.generate(n).size.should == n
41
+ end
42
+ end
43
+
44
+ describe "#next_depth" do
45
+ it "gets depth from self" do
46
+ subject.oscil.should_receive(:next)
47
+ subject.send(:next_depth)
48
+ end
49
+ end
50
+ end
51
+
52
+ context "modulation not enabled" do
53
+ before { subject.mod_enabled = false }
54
+
55
+ describe "#next_depth" do
56
+ it "gets depth from Oscillator" do
57
+ subject.should_receive(:depth)
58
+ subject.send(:next_depth)
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "#format_text (private)" do
65
+ subject { generator }
66
+
67
+ it "converts \\r to \\n" do
68
+ subject.send(:format_text, "a\rb").should == "a\nb"
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ describe Charosc::Markov do
4
+ let(:chars) { "abcabcdabcdeabcdefabcdefg".scan(/./) }
5
+ let(:markov) { described_class.new(chars) }
6
+
7
+ describe "#get_sequence" do
8
+ it "raises if depth is > 1" do
9
+ expect { markov.get_sequence("a", 0) }.to raise_error(ArgumentError)
10
+ end
11
+
12
+ describe "get a possible sequence after start_obj" do
13
+ let(:a2) { markov.get_sequence("a", 2) }
14
+ let(:a3) { markov.get_sequence("a", 3) }
15
+ let(:b3) { markov.get_sequence("b", 3) }
16
+ let(:f5) { markov.get_sequence("f", 5) }
17
+ let(:g6) { markov.get_sequence("g", 6) }
18
+
19
+ 20.times do
20
+ specify { [%w{b c}].should include(a2) }
21
+ specify { [%w{b c a}, %w{b c d}].should include(a3) }
22
+ specify { [%w{c a b}, %w{c d a}, %w{c d e}].should include(b3) }
23
+ specify { [%w{a b c d e}, %w{g a b c a}].should include(f5) }
24
+ specify { [%w{a b c a b c}].should include(g6) }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+
3
+ describe Charosc::Oscillator do
4
+ describe "#next" do
5
+ context "1, top: 5, bottom: 1, inc: 1" do
6
+ let(:osc) { described_class.new(1, top: 5, bottom: 1, inc: 1) }
7
+
8
+ it "steps through values" do
9
+ [2, 3, 4, 5, 4, 3, 2, 1, 2, 3].each_with_index do |val, ndx|
10
+ osc.next.should == val
11
+ end
12
+ end
13
+ end
14
+
15
+ context "33, top: 5, bottom: 1, inc: 1" do
16
+ let(:osc) { described_class.new(33, top: 5, bottom: 1, inc: 1) }
17
+
18
+ it "steps through values" do
19
+ [4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2].each_with_index do |val, ndx|
20
+ osc.next.should == val
21
+ end
22
+ end
23
+ end
24
+
25
+ context "1, top: 10, bottom: 3, inc: 0.2" do
26
+ let(:osc) { described_class.new(1, top: 10, bottom: 3, inc: 0.2) }
27
+
28
+ it "steps through values" do
29
+ [3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6].each_with_index do |val, ndx|
30
+ osc.next.should == val
31
+ end
32
+ end
33
+ end
34
+
35
+ context "499, top: 500, bottom: 5, inc: 1" do
36
+ let(:osc) { described_class.new(499, top: 500, bottom: 5, inc: 1) }
37
+
38
+ it "steps through values" do
39
+ [500, 499, 498, 497, 496].each_with_index do |val, ndx|
40
+ osc.next.should == val
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+
3
+ describe Charosc::Text do
4
+ let(:text) { described_class.new("abc defA ghijB") }
5
+
6
+ describe "#chars" do
7
+ end
8
+
9
+ describe "#words" do
10
+ it "returns string split on whitespace" do
11
+ text.words.should == ["abc", "defA", "ghijB"]
12
+ end
13
+ end
14
+
15
+ describe "#chars" do
16
+ it "returns array of chars" do
17
+ text.chars.should == [
18
+ "a", "b", "c", " ", "d", "e", "f", "A", " ", "g", "h", "i", "j", "B"
19
+ ]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,6 @@
1
+ require "charosc"
2
+ require "rspec"
3
+
4
+ RSpec.configure do |c|
5
+ c.color_enabled = true
6
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: charosc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dan Richert
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: weighted_randomizer
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.1.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.1.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: trollop
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.13'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.13'
46
+ - !ruby/object:Gem::Dependency
47
+ name: ruby-progressbar
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.0.2
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.12'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.12'
78
+ description: Oscillating Markov text generator
79
+ email:
80
+ - dan.richert@gmail.com
81
+ executables:
82
+ - charosc
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - .travis.yml
88
+ - Gemfile
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - bin/charosc
93
+ - charosc.gemspec
94
+ - lib/charosc.rb
95
+ - lib/charosc/generator.rb
96
+ - lib/charosc/markov.rb
97
+ - lib/charosc/oscillator.rb
98
+ - lib/charosc/text.rb
99
+ - lib/charosc/version.rb
100
+ - share/pg12299.orig.txt
101
+ - share/the-mechanical-properties-of-wood.txt
102
+ - spec/charosc/generator_spec.rb
103
+ - spec/charosc/markov_spec.rb
104
+ - spec/charosc/oscillator_spec.rb
105
+ - spec/charosc/text_spec.rb
106
+ - spec/spec_helper.rb
107
+ homepage: ''
108
+ licenses: []
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 1.8.23
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: Oscillating Markov text generator
131
+ test_files:
132
+ - spec/charosc/generator_spec.rb
133
+ - spec/charosc/markov_spec.rb
134
+ - spec/charosc/oscillator_spec.rb
135
+ - spec/charosc/text_spec.rb
136
+ - spec/spec_helper.rb
137
+ has_rdoc: