scrambler 0.0.5 → 0.0.6

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.
@@ -2,4 +2,5 @@ require "scrambler/version"
2
2
  require "scrambler/core_ext"
3
3
 
4
4
  require "scrambler/cube"
5
- require "scrambler/pyraminx"
5
+ require "scrambler/pyraminx"
6
+ require "scrambler/clock"
@@ -0,0 +1,20 @@
1
+ module Scrambler
2
+ class Clock
3
+ def scramble
4
+ pins = %w(U d)
5
+ states = %w(UUdd dUdU ddUU UdUd dUUU UdUU UUUd UUdU UUUU dddd)
6
+ scramble = states.map do |state|
7
+ moves = []
8
+ u = rand(12) - 5
9
+ d = rand(12) - 5
10
+ moves << 'u=' + u.to_s if state.gsub('d', '').length > 1
11
+ moves << 'd=' + d.to_s if state.gsub('U', '').length > 1
12
+ state + ' ' + moves.join('; ')
13
+ end
14
+ scramble << Array.new(4).map do
15
+ pins.sample
16
+ end.join
17
+ scramble.join(' / ')
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,4 @@
1
+ # borrowed from activesupport
1
2
  class Array
2
3
  def sample(n=nil)
3
4
  return self[Kernel.rand(size)] if n.nil?
@@ -1,3 +1,3 @@
1
1
  module Scrambler
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+
3
+ describe Scrambler::Clock do
4
+ it "should scramble using all pin combinations" do
5
+ scramble = subject.scramble
6
+ scramble.should include("UUdd")
7
+ scramble.should include("dUdU")
8
+ scramble.should include("ddUU")
9
+ scramble.should include("UdUd")
10
+ scramble.should include("dUUU")
11
+ scramble.should include("UdUU")
12
+ scramble.should include("UUdU")
13
+ scramble.should include("UUUd")
14
+ scramble.should include("UUUU")
15
+ scramble.should include("dddd")
16
+ end
17
+
18
+ it "should have 9 u and 5 d turns" do
19
+ scramble = subject.scramble
20
+ scramble.scan(/u=-?\d+/).should have(9).elements
21
+ scramble.scan(/d=-?\d+/).should have(5).elements
22
+ end
23
+
24
+ it "should only turn clocks between -5 and 6 hours" do
25
+ 10.times do
26
+ subject.scramble.scan(/u=(-?\d+)/) do |value|
27
+ (-5..6).should include(value.first.to_i) # test for value being a number
28
+ end
29
+ end
30
+ end
31
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: scrambler
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.5
5
+ version: 0.0.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tim Habermaas
@@ -23,7 +23,7 @@ dependencies:
23
23
  version: 2.6.0
24
24
  type: :development
25
25
  version_requirements: *id001
26
- description: Scrambler provides scrambles for all WCA puzzles
26
+ description: Scrambler for cubes and other puzzles
27
27
  email: t.habermaas@gmail.com
28
28
  executables: []
29
29
 
@@ -32,11 +32,13 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
 
34
34
  files:
35
+ - lib/scrambler/clock.rb
35
36
  - lib/scrambler/core_ext.rb
36
37
  - lib/scrambler/cube.rb
37
38
  - lib/scrambler/pyraminx.rb
38
39
  - lib/scrambler/version.rb
39
40
  - lib/scrambler.rb
41
+ - spec/scrambler/clock_spec.rb
40
42
  - spec/scrambler/five_by_five_spec.rb
41
43
  - spec/scrambler/four_by_four_spec.rb
42
44
  - spec/scrambler/pyraminx_spec.rb