Skip to content

Instantly share code, notes, and snippets.

@zspencer
Created January 23, 2015 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zspencer/15621ac7c9451f3ac343 to your computer and use it in GitHub Desktop.
Save zspencer/15621ac7c9451f3ac343 to your computer and use it in GitHub Desktop.
Notes/Kata from CodeUnion Pro-engineering session 2015-01-22

Agenda: 6:00 ~ 6:10 - Review of last session concepts (TDD, Refactoring, 4 Rules of Simple Design) 6:10 ~ 7:00 - Mob programming on the Roman Numerals Kata, swapping drivers every 15m 7:00 ~ 7:05 - Break! 7:05 ~7:55 - Mob-programming on Roman Numerals Kata, swapping drivers ever 15m 7:55 ~ 8:00 - Reflect! How is our mental model of programming sharper at the end of the session than at the beginning?

Notes!

Simplicity Ruiles - http://c2.com/cgi/wiki?XpSimplicityRules

What's the difference between BDD and TDD: Mostly marketing,

TDD Cycle: Red, Green, Refactor

Yard - http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md

Sublime: To format your .rb file command + shift + p Indentation: Reindent Lines

Inside hash: { "I": 1 } => converts String("I") to Symbol

x in front of an it statement will pend out that test, test will return 'pending'

require 'rspec'
describe "numeral_to_number" do
it "returns 1 for roman numeral I" do
expect(numeral_to_number("I")).to(eq(1))
end
it "returns 2 for roman numeral II" do
expect(numeral_to_number("II")).to(eq(2))
end
it "returns 5 for roman numeral V" do
expect(numeral_to_number("V")).to(eq(5))
end
it "returns 10 for roman numeral X" do
expect(numeral_to_number("X")).to(eq(10))
end
it "returns 4 for roman numeral IV" do
expect(numeral_to_number("IV")).to(eq(4))
end
it "returns 19 for XIX" do
expect(numeral_to_number("XIX")).to(eq(19))
end
it "returns 50 for L" do
expect(numeral_to_number("L")).to(eq(50))
end
it "returns 100 for C" do
expect(numeral_to_number("C")).to(eq(100))
end
it "returns 500 for D" do
expect(numeral_to_number("D")).to(eq(500))
end
it "returns 1000 for M" do
expect(numeral_to_number("M")).to(eq(1000))
end
it "returns 2015 for MMXV" do
expect(numeral_to_number("MMXV")).to(eq(2015))
end
it "returns 2389 for MMCCCLXXXIX" do
expect(numeral_to_number("MMCCCLXXXIX")).to(eq(2389))
end
it "returns 1949 for MCMXLIX" do
expect(numeral_to_number("MCMXLIX")).to(eq(1949))
end
end
# Translates roman numeral into arabic number.
#
# @example
# numeral_to_number("MMXV") #=> 2015
# numeral_to_number("CMXLXCIV") #=> 1999
#
# @param numeral [String] Roman numeral
# @return [Integer]
def numeral_to_number(numerals)
numeral_map = {
"M" => 1000,
"CM" => 900,
"D" => 500,
"CD" => 400,
"C" => 100,
"XC" => 90,
"L" => 50,
"XL" => 40,
"X" => 10,
"IX" => 9,
"IV" => 4,
"V" => 5,
"I" => 1,
}
value = 0
while !numerals.empty?
numeral_map.each_pair do |numeral, arabic_value|
if(numerals.start_with?(numeral))
numerals.slice!(0, numeral.length)
value += arabic_value
end
end
end
value
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment