Skip to content

Commit afcbf69

Browse files
committed
add gemfile; styling fixes
1 parent 6d054ba commit afcbf69

12 files changed

+121
-122
lines changed

Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
gem "ProcessPilot"
4+
gem "minitest"

Gemfile.lock

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
ProcessPilot (2.0.0.20120301)
5+
rUtilAnts (>= 1.0)
6+
minitest (5.14.2)
7+
rUtilAnts (2.0.0.20130827)
8+
9+
PLATFORMS
10+
ruby
11+
12+
DEPENDENCIES
13+
ProcessPilot
14+
minitest
15+
16+
BUNDLED WITH
17+
2.1.4

advanced_hello.rb

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@
22

33
# What is your name? tom
44
# What is your home town? oxford
5-
# What country is that in? uk
5+
# What country is that in? uk
66
# Hello Tom! You are from Oxford, UK.
77

8-
# What is your name? boRIS
8+
# What is your name? igor
99
# What is your home town? Minsk
1010
# What country is that in? Belarus
11-
# Hello Boris! Your are from Minsk, BELARUS.
12-
11+
# Hello Igor! Your are from Minsk, BELARUS.
1312

1413
# Get their name
15-
print "What is your name? "
14+
print 'What is your name? '
1615
name = gets.chomp
1716

1817
# Get their home town
1918

20-
# Get thier country
19+
# Get their country
2120

2221
# Say hello

divide_cake.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

77
# (You don't need to worry about bad input. Just assume that your user will be nice!)
88

9-
10-
print "How many pieces does you cake have? "
9+
print 'How many pieces does you cake have? '
1110
# Get the number. to_i converts a string into an integer.
1211
num_cake_pieces = gets.chomp.to_i
1312

14-
print "How many people want some cake? "
13+
print 'How many people want some cake? '
1514
# Get the number. Conver it to an integer.
1615

17-
1816
# Print the solution

explain.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
require_relative 'special_ops'
22

3-
print "Enter your first integer: "
3+
print 'Enter your first integer: '
44
n1 = gets.chomp.to_i
55

6-
print "Enter your second integer: "
6+
print 'Enter your second integer: '
77
n2 = gets.chomp.to_i
88

99
bitwise_and(n1, n2)
1010

11-
puts ""
11+
puts ''
1212

1313
bitwise_xor(n1, n2)
1414

15-
puts ""
15+
puts ''

hello.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
# print 'Hello' to the screen
2-
puts "Hello"
3-
2+
puts 'Hello'

hello_you.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# print is like puts, except it doesn't start a new line after printing
2-
print "Enter your name: "
2+
print 'Enter your name: '
33
# gets stands for "get string". It waits for the user to enter some text and hit Enter.
44
name = gets
5-
# chomp is a method that will remove any newline characters from the end of our string
5+
# chomp is a method that will remove any newline characters from the end of our string
66
name = name.chomp
77

88
puts name
9-
10-

special_ops.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
# puts a 1 in that position in the output if they are both 1s. Otherwise
44
# it puts a 0.
55
def bitwise_and(x, y)
6-
ans = x&y
7-
# rjust(5) pads the string with spaces (on the left) up to a length of 5
8-
puts x.to_s.rjust(5) + " = " + x.to_s(2).rjust(8,'0')
9-
puts y.to_s.rjust(5) + " = " + y.to_s(2).rjust(8,'0')
10-
puts (x.to_s + "&" + y.to_s).rjust(5) + " = " + ans.to_s(2).rjust(8, '0') + " = " + ans.to_s
6+
ans = x & y
7+
# rjust(5) pads the string with spaces (on the left) up to a length of 5
8+
puts x.to_s.rjust(5) + ' = ' + x.to_s(2).rjust(8, '0')
9+
puts y.to_s.rjust(5) + ' = ' + y.to_s(2).rjust(8, '0')
10+
puts (x.to_s + '&' + y.to_s).rjust(5) + ' = ' + ans.to_s(2).rjust(8, '0') + ' = ' + ans.to_s
1111
end
1212

1313
# ^ is the bitwise xor operation. It operates on numbers in their binary representation.
1414
# It takes a pair of bits at a given position in the input numbers and
1515
# puts a 1 in that position in the output if exactly one is a 1. Otherwise
1616
# it puts a 0.
1717
def bitwise_xor(x, y)
18-
ans = x^y
19-
# rjust(5) pads the string with spaces (on the left) up to a length of 5
20-
puts x.to_s.rjust(5) + " = " + x.to_s(2).rjust(8,'0')
21-
puts y.to_s.rjust(5) + " = " + y.to_s(2).rjust(8,'0')
22-
puts (x.to_s + "^" + y.to_s).rjust(5) + " = " + ans.to_s(2).rjust(8, '0') + " = " + ans.to_s
23-
end
18+
ans = x ^ y
19+
# rjust(5) pads the string with spaces (on the left) up to a length of 5
20+
puts x.to_s.rjust(5) + ' = ' + x.to_s(2).rjust(8, '0')
21+
puts y.to_s.rjust(5) + ' = ' + y.to_s(2).rjust(8, '0')
22+
puts (x.to_s + '^' + y.to_s).rjust(5) + ' = ' + ans.to_s(2).rjust(8, '0') + ' = ' + ans.to_s
23+
end

strings.rb

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
a = "Hello"
1+
a = 'Hello'
32

43
a.reverse
54

@@ -9,19 +8,18 @@
98

109
a.downcase
1110

12-
b = "dave"
11+
b = 'dave'
1312

1413
b.capitalize
1514

1615
a + b
1716

18-
a + " " + b
17+
a + ' ' + b
1918

2019
b.capitalize!
2120

22-
a + " " + b
21+
a + ' ' + b
2322

2423
a * 3
2524

2625
3 * a
27-

test_advanced_hello.rb

+22-26
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,30 @@
44

55
# Try to load processpilot. Tell user to install if they don't have it.
66
begin
7-
require 'processpilot/processpilot'
7+
require 'processpilot/processpilot'
88
rescue LoadError
9-
error_string = <<EOF
10-
Oh dear .. it didn't work. To run tests you must install ProcessPilot:
11-
12-
gem install ProcessPilot
13-
14-
EOF
15-
puts error_string
16-
exit
9+
error_string = <<~EOF
10+
Oh dear .. it didn't work. To run tests you must install ProcessPilot:
11+
#{' '}
12+
gem install ProcessPilot
13+
#{' '}
14+
EOF
15+
puts error_string
16+
exit
1717
end
1818

1919
# The actual test
2020
describe 'advanced_hello' do
21-
it "works for a random name" do
22-
ProcessPilot::pilot('advanced_hello.rb', :force_ruby_process_sync => true, :debug=> true) do |oStdin, iStdout|
23-
iStdout.readpartial(100) # => "Enter your name: "
24-
oStdin.write("daVE\n")
25-
iStdout.readpartial(100) # => What is your home town?
26-
oStdin.write("vienna\n")
27-
iStdout.readpartial(100) # => What country is that in?
28-
oStdin.write("austria\n")
29-
output = iStdout.gets.chomp # => "Hello Boris the newt"
30-
assert_equal "Hello Dave! You are from Vienna, AUSTRIA.", output
31-
32-
end
33-
34-
end
35-
36-
37-
end
21+
it 'works for a random name' do
22+
ProcessPilot.pilot('advanced_hello.rb', force_ruby_process_sync: true, debug: true) do |stdin, stdout|
23+
stdout.readpartial(100) # => "Enter your name: "
24+
stdin.write("daVE\n")
25+
stdout.readpartial(100) # => What is your home town?
26+
stdin.write("vienna\n")
27+
stdout.readpartial(100) # => What country is that in?
28+
stdin.write("austria\n")
29+
output = stdout.gets.chomp # => "Hello Boris the newt"
30+
assert_equal 'Hello Dave! You are from Vienna, AUSTRIA.', output
31+
end
32+
end
33+
end

test_divide_cake.rb

+30-36
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,38 @@
44

55
# Try to load processpilot. Tell user to install if they don't have it.
66
begin
7-
require 'processpilot/processpilot'
7+
require 'processpilot/processpilot'
88
rescue LoadError
9-
error_string = <<EOF
10-
Oh dear .. it didn't work. To run tests you must install ProcessPilot:
11-
12-
gem install ProcessPilot
13-
14-
EOF
15-
puts error_string
16-
exit
9+
error_string = <<~EOF
10+
Oh dear .. it didn't work. To run tests you must install ProcessPilot:
11+
#{' '}
12+
gem install ProcessPilot
13+
#{' '}
14+
EOF
15+
puts error_string
16+
exit
1717
end
1818

1919
# The actual test
2020
describe 'divide_cake' do
21-
it "works for 11 and 3" do
22-
ProcessPilot::pilot('divide_cake.rb', :force_ruby_process_sync => true) do |oStdin, iStdout|
23-
iStdout.readpartial(100) # => How many pieces of cake do you have? 11
24-
oStdin.write("11\n")
25-
iStdout.readpartial(100) # => How many people want some cake? 3
26-
oStdin.write("3\n")
27-
output = iStdout.gets.chomp # =>
28-
assert_equal "Give each person 3 pieces. There will be 2 additional pieces for you to eat as soon as they leave.", output
29-
30-
end
31-
32-
end
33-
it "works for 4 and 5" do
34-
ProcessPilot::pilot('divide_cake.rb', :force_ruby_process_sync => true) do |oStdin, iStdout|
35-
iStdout.readpartial(100) # => How many pieces of cake do you have? 11
36-
oStdin.write("4\n")
37-
iStdout.readpartial(100) # => How many people want some cake? 3
38-
oStdin.write("5\n")
39-
output = iStdout.gets.chomp # =>
40-
assert_equal "Give each person 0 pieces. There will be 4 additional pieces for you to eat as soon as they leave.", output
41-
42-
end
43-
44-
end
45-
46-
47-
end
21+
it 'works for 11 and 3' do
22+
ProcessPilot.pilot('divide_cake.rb', force_ruby_process_sync: true) do |stdin, stdout|
23+
stdout.readpartial(100) # => How many pieces of cake do you have? 11
24+
stdin.write("11\n")
25+
stdout.readpartial(100) # => How many people want some cake? 3
26+
stdin.write("3\n")
27+
output = stdout.gets.chomp # =>
28+
assert_equal 'Give each person 3 pieces. There will be 2 additional pieces for you to eat as soon as they leave.', output
29+
end
30+
end
31+
it 'works for 4 and 5' do
32+
ProcessPilot.pilot('divide_cake.rb', force_ruby_process_sync: true) do |stdin, stdout|
33+
stdout.readpartial(100) # => How many pieces of cake do you have? 11
34+
stdin.write("4\n")
35+
stdout.readpartial(100) # => How many people want some cake? 3
36+
stdin.write("5\n")
37+
output = stdout.gets.chomp # =>
38+
assert_equal 'Give each person 0 pieces. There will be 4 additional pieces for you to eat as soon as they leave.', output
39+
end
40+
end
41+
end

test_hello_you.rb

+19-23
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,27 @@
44

55
# Try to load processpilot. Tell user to install if they don't have it.
66
begin
7-
require 'processpilot/processpilot'
7+
require 'processpilot/processpilot'
88
rescue LoadError
9-
error_string = <<EOF
10-
Oh dear .. it didn't work. To run tests you must install ProcessPilot:
11-
12-
gem install ProcessPilot
13-
14-
EOF
15-
puts error_string
16-
exit
9+
error_string = <<~EOF
10+
Oh dear .. it didn't work. To run tests you must install ProcessPilot:
11+
#{' '}
12+
gem install ProcessPilot
13+
#{' '}
14+
EOF
15+
puts error_string
16+
exit
1717
end
1818

1919
# The actual test
2020
describe 'hello_you' do
21-
it "works for a random name" do
22-
ProcessPilot::pilot('hello_you.rb', :force_ruby_process_sync => true) do |oStdin, iStdout|
23-
iStdout.readpartial(100) # => "Enter your name: "
24-
oStdin.write("Boris the Newt\n")
25-
26-
output = iStdout.gets.chomp # => "Hello Boris the newt"
27-
assert_equal "Hello Boris the Newt", output
28-
29-
end
30-
31-
end
32-
33-
34-
end
21+
it 'works for a random name' do
22+
ProcessPilot.pilot('hello_you.rb', force_ruby_process_sync: true) do |stdin, stdout|
23+
stdout.readpartial(100) # => "Enter your name: "
24+
stdin.write("Adam Smith\n")
25+
26+
output = stdout.gets.chomp
27+
assert_equal 'Hello Adam Smith', output
28+
end
29+
end
30+
end

0 commit comments

Comments
 (0)