main
1#given a graph, output each level of friends.
2#each friend should only be output once, at the first level they are encountered.
3
4=begin
5INPUT
62 # number of lines to follow
7A:B,C,D # member a has friends b,c,d
8A # the member to start the traversal from.
9
10OUTPUT
11=end
12
13require 'social_graph'
14
15describe "problem" do
16 subject { SocialGraph.new(input, output) }
17 let(:output) { StringIO.new }
18
19 context "when 2 lines given" do
20 let(:fixtures_dir) { File.join(Dir.pwd, 'spec', 'fixtures') }
21 let(:input) { StringIO.new(IO.read(File.join(fixtures_dir, "input001.txt"))) }
22 let(:expected) { IO.read(File.join(fixtures_dir, "output001.txt")) }
23
24 it 'writes the correct result' do
25 subject.run
26 output.rewind
27 expect(output.read).to eql(expected)
28 end
29 end
30
31 context "when 4 lines given" do
32 let(:fixtures_dir) { File.join(Dir.pwd, 'spec', 'fixtures') }
33 let(:input) { StringIO.new(IO.read(File.join(fixtures_dir, "input002.txt"))) }
34 let(:expected) { IO.read(File.join(fixtures_dir, "output002.txt")) }
35
36 it 'writes the correct result' do
37 subject.run
38 output.rewind
39 expect(output.read).to eql(expected)
40 end
41 end
42
43 context "when 7 lines given" do
44 let(:fixtures_dir) { File.join(Dir.pwd, 'spec', 'fixtures') }
45 let(:input) { StringIO.new(IO.read(File.join(fixtures_dir, "input000.txt"))) }
46 let(:expected) { IO.read(File.join(fixtures_dir, "output000.txt")) }
47
48 it 'writes the correct result' do
49 subject.run
50 output.rewind
51 expect(output.read).to eql(expected)
52 end
53 end
54end