-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpermutations_spec.rb
More file actions
71 lines (66 loc) · 1.62 KB
/
permutations_spec.rb
File metadata and controls
71 lines (66 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Written by Elisabeth Hendrickson, Quality Tree Software, Inc.
# Copyright (c) 2009 Quality Tree Software, Inc.
#
# This work is licensed under the
# Creative Commons Attribution 3.0 United States License.
#
# To view a copy of this license, visit
# http://creativecommons.org/licenses/by/3.0/us/
#
# or send a letter to:
# Creative Commons
# 171 Second Street
# Suite 300
# San Francisco, California, 94105
# USA.
require 'rubygems'
require 'spec'
require 'permutations'
require 'pp'
describe "permutations" do
it "should be able to give the 2 permutations for an array of length 2" do
permute([1,2]).sort.should == [[1,2], [2,1]]
end
it "should be able to give the 6 permutations for an array of length 3" do
permute([1,2,3]).sort.should == [
[1,2,3],
[1,3,2],
[2,1,3],
[2,3,1],
[3,1,2],
[3,2,1]
]
end
it "should be able to give the 24 permutations for an array of length 4" do
permute([1,2,3,4]).sort.should == [
[1,2,3,4],
[1,2,4,3],
[1,3,2,4],
[1,3,4,2],
[1,4,2,3],
[1,4,3,2],
[2,1,3,4],
[2,1,4,3],
[2,3,1,4],
[2,3,4,1],
[2,4,1,3],
[2,4,3,1],
[3,1,2,4],
[3,1,4,2],
[3,2,1,4],
[3,2,4,1],
[3,4,1,2],
[3,4,2,1],
[4,1,2,3],
[4,1,3,2],
[4,2,1,3],
[4,2,3,1],
[4,3,1,2],
[4,3,2,1]
]
end
it "should be able to give the buhzillion permutations for an array of lenght 9 in a reasonable time" do
variations = permute([1,2,3,4,5,6,7,8,9])
variations.include?([9,8,7,6,5,4,3,2,1]).should be_true
end
end