main
1require "spec_helper"
2
3describe QuickFind do
4 subject { QuickFind.new(10) }
5
6 it "is not connected by default" do
7 10.times do |n|
8 expect(subject.connected?(n, n+1)).to be_falsey
9 end
10 end
11
12 it "is connected" do
13 subject.union(0, 1)
14 expect(subject.connected?(0, 1)).to be_truthy
15 end
16
17 it "unions and connects properly" do
18 subject.union(4, 3)
19 expect(subject.connected?(4, 3)).to be_truthy
20 expect(subject.connected?(3, 4)).to be_truthy
21
22 subject.union(3, 8)
23 expect(subject.connected?(3, 8)).to be_truthy
24
25 subject.union(6, 5)
26 expect(subject.connected?(6, 5)).to be_truthy
27
28 subject.union(9, 4)
29 expect(subject.connected?(9, 4)).to be_truthy
30
31 subject.union(2, 1)
32 expect(subject.connected?(2, 1)).to be_truthy
33
34 subject.union(8, 9)
35 expect(subject.connected?(8, 9)).to be_truthy
36
37 expect(subject.connected?(5, 0)).to be_falsey
38 subject.union(5, 0)
39 expect(subject.connected?(5, 0)).to be_truthy
40 expect(subject.connected?(6, 0)).to be_truthy
41 expect(subject.connected?(5, 6)).to be_truthy
42
43 subject.union(7, 2)
44 subject.union(6, 1)
45
46 tuples = [
47 [0, 5],
48 [5, 6],
49 [6, 1],
50 [1, 2],
51 [2, 7],
52 [8, 3],
53 [3, 4],
54 [4, 9],
55 ]
56 tuples.each do |tuple|
57 expect(subject.connected?(tuple.first, tuple.last)).to be_truthy
58 end
59 end
60end