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
|
#given a graph, output each level of friends.
#each friend should only be output once, at the first level they are encountered.
=begin
INPUT
2 # number of lines to follow
A:B,C,D # member a has friends b,c,d
A # the member to start the traversal from.
OUTPUT
=end
require 'social_graph'
describe "problem" do
subject { SocialGraph.new(input, output) }
let(:output) { StringIO.new }
context "when 2 lines given" do
let(:fixtures_dir) { File.join(Dir.pwd, 'spec', 'fixtures') }
let(:input) { StringIO.new(IO.read(File.join(fixtures_dir, "input001.txt"))) }
let(:expected) { IO.read(File.join(fixtures_dir, "output001.txt")) }
it 'writes the correct result' do
subject.run
output.rewind
expect(output.read).to eql(expected)
end
end
context "when 4 lines given" do
let(:fixtures_dir) { File.join(Dir.pwd, 'spec', 'fixtures') }
let(:input) { StringIO.new(IO.read(File.join(fixtures_dir, "input002.txt"))) }
let(:expected) { IO.read(File.join(fixtures_dir, "output002.txt")) }
it 'writes the correct result' do
subject.run
output.rewind
expect(output.read).to eql(expected)
end
end
context "when 7 lines given" do
let(:fixtures_dir) { File.join(Dir.pwd, 'spec', 'fixtures') }
let(:input) { StringIO.new(IO.read(File.join(fixtures_dir, "input000.txt"))) }
let(:expected) { IO.read(File.join(fixtures_dir, "output000.txt")) }
it 'writes the correct result' do
subject.run
output.rewind
expect(output.read).to eql(expected)
end
end
end
|