Created
August 3, 2014 13:57
-
-
Save adrianbadarau/6067b2cb57a2f77793d2 to your computer and use it in GitHub Desktop.
Lear_ruby_TDD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.idea | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TDD_learn_ruby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<Settings><!--This file was automatically generated by Ruby plugin. | |
You are allowed to: | |
1. Remove rake task | |
2. Add existing rake tasks | |
To add existing rake tasks automatically delete this file and reload the project. | |
--><RakeGroup description="" fullCmd="" taksId="rake" /></Settings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" /> | |
</project> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectRootManager" version="2" project-jdk-name="ruby-2.0.0-p481 (1)" project-jdk-type="RUBY_SDK" /> | |
</project> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectModuleManager"> | |
<modules> | |
<module fileurl="file://$PROJECT_DIR$/.idea/TDD_learn_ruby.iml" filepath="$PROJECT_DIR$/.idea/TDD_learn_ruby.iml" /> | |
</modules> | |
</component> | |
</project> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<component name="DependencyValidationManager"> | |
<state> | |
<option name="SKIP_IMPORT_STATEMENTS" value="false" /> | |
</state> | |
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<module type="RUBY_MODULE" version="4"> | |
<component name="ModuleRunConfigurationManager"> | |
<configuration default="false" name="Run spec 'temperature_spec': TDD_learn_ruby" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true"> | |
<predefined_log_file id="RUBY_RSPEC" enabled="true" /> | |
<module name="TDD_learn_ruby" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$/01_temperature" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" /> | |
<envs> | |
<env name="JRUBY_OPTS" value="-X+O" /> | |
</envs> | |
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" /> | |
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" /> | |
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov" /> | |
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/01_temperature/temperature_spec.rb" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" /> | |
<RunnerSettings RunnerId="RubyRunner" /> | |
<ConfigurationWrapper RunnerId="RubyRunner" /> | |
<method /> | |
</configuration> | |
<configuration default="false" name="Run spec 'calculator_spec': TDD_learn_ruby" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true"> | |
<predefined_log_file id="RUBY_RSPEC" enabled="true" /> | |
<module name="TDD_learn_ruby" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$/02_calculator" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" /> | |
<envs> | |
<env name="JRUBY_OPTS" value="-X+O" /> | |
</envs> | |
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" /> | |
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" /> | |
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov" /> | |
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/02_calculator/calculator_spec.rb" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" /> | |
<RunnerSettings RunnerId="RubyRunner" /> | |
<ConfigurationWrapper RunnerId="RubyRunner" /> | |
<method /> | |
</configuration> | |
<configuration default="false" name="Run spec 'simon_says_spec': TDD_learn_ruby" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true"> | |
<predefined_log_file id="RUBY_RSPEC" enabled="true" /> | |
<module name="TDD_learn_ruby" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$/03_simon_says" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" /> | |
<envs> | |
<env name="JRUBY_OPTS" value="-X+O" /> | |
</envs> | |
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" /> | |
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" /> | |
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov" /> | |
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/03_simon_says/simon_says_spec.rb" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" /> | |
<RunnerSettings RunnerId="RubyRunner" /> | |
<ConfigurationWrapper RunnerId="RubyRunner" /> | |
<method /> | |
</configuration> | |
<configuration default="false" name="Run spec 'pig_latin_spec': TDD_learn_ruby" type="RSpecRunConfigurationType" factoryName="RSpec"> | |
<predefined_log_file id="RUBY_RSPEC" enabled="true" /> | |
<module name="TDD_learn_ruby" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$/04_pig_latin" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" /> | |
<envs> | |
<env name="JRUBY_OPTS" value="-X+O" /> | |
</envs> | |
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" /> | |
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" /> | |
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov" /> | |
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/04_pig_latin/pig_latin_spec.rb" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" /> | |
<RunnerSettings RunnerId="RubyRunner" /> | |
<ConfigurationWrapper RunnerId="RubyRunner" /> | |
<method /> | |
</configuration> | |
<configuration default="false" name="Run spec 'book_titles_spec': TDD_learn_ruby" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true"> | |
<predefined_log_file id="RUBY_RSPEC" enabled="true" /> | |
<module name="TDD_learn_ruby" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$/08_book_titles" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" /> | |
<envs> | |
<env name="JRUBY_OPTS" value="-X+O" /> | |
</envs> | |
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" /> | |
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" /> | |
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov" /> | |
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/08_book_titles/book_titles_spec.rb" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" /> | |
<RunnerSettings RunnerId="RubyRunner" /> | |
<ConfigurationWrapper RunnerId="RubyRunner" /> | |
<method /> | |
</configuration> | |
<configuration default="false" name="Run spec 'timer_spec': TDD_learn_ruby" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true"> | |
<predefined_log_file id="RUBY_RSPEC" enabled="true" /> | |
<module name="TDD_learn_ruby" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$/09_timer" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" /> | |
<envs> | |
<env name="JRUBY_OPTS" value="-X+O" /> | |
</envs> | |
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" /> | |
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" /> | |
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov" /> | |
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/09_timer/timer_spec.rb" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" /> | |
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" /> | |
<RunnerSettings RunnerId="RubyRunner" /> | |
<ConfigurationWrapper RunnerId="RubyRunner" /> | |
<method /> | |
</configuration> | |
</component> | |
<component name="NewModuleRootManager"> | |
<content url="file://$MODULE_DIR$" /> | |
<orderEntry type="inheritedJdk" /> | |
<orderEntry type="sourceFolder" forTests="false" /> | |
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.6.5, ruby-2.0.0-p481 (1)) [gem]" level="application" /> | |
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, ruby-2.0.0-p481 (1)) [gem]" level="application" /> | |
<orderEntry type="library" scope="PROVIDED" name="rake (v10.3.2, ruby-2.0.0-p481 (1)) [gem]" level="application" /> | |
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.0.0, ruby-2.0.0-p481 (1)) [gem]" level="application" /> | |
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.0.3, ruby-2.0.0-p481 (1)) [gem]" level="application" /> | |
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.0.3, ruby-2.0.0-p481 (1)) [gem]" level="application" /> | |
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.0.3, ruby-2.0.0-p481 (1)) [gem]" level="application" /> | |
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.0.3, ruby-2.0.0-p481 (1)) [gem]" level="application" /> | |
</component> | |
</module> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="VcsDirectoryMappings"> | |
<mapping directory="$PROJECT_DIR$" vcs="Git" /> | |
</component> | |
</project> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hello | |
hello = "Hello!" | |
end | |
def greet(name) | |
return "Hello, #{name}!" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Hello! | |
# | |
# This lab teaches basic Ruby function syntax. | |
# | |
# ## Open a terminal in this directory | |
# | |
# cd 00_hello | |
# | |
# This directory is the starting point for this exercise. It contains a spec file and you'll be adding a ruby file to (eventually) make the specs pass. | |
# | |
# ## Run the test | |
# | |
# rake | |
# | |
# ## Watch it fail | |
# | |
# You should see an error. **Don't get scared!** Try to read it and figure out what the computer wants to tell you. Somewhere on the first line it should say something like | |
# | |
# no such file to load -- test-first-teaching/hello/hello (LoadError) | |
# | |
# That means that it is looking for a file called `hello.rb` and can't find it. | |
# | |
# ## Create hello.rb | |
# | |
# Open up `hello.rb` in a text editor. Save it. Run the test again. | |
# | |
# rake | |
# | |
# ## Watch it fail | |
# | |
# Now you should see an error like this: | |
# | |
# the hello function | |
# says hello (FAILED - 1) | |
# | |
# Failures: | |
# | |
# 1) the hello function says hello | |
# Failure/Error: hello.should == "Hello!" | |
# NameError: | |
# undefined local variable or method `hello' for #<RSpec::Core::ExampleGroup::Nested_1:0x000001009b8808> | |
# # ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>' | |
# | |
# ## Create the hello function | |
# | |
# Fix this by opening `hello.rb` and creating an empty function: | |
# | |
# def hello | |
# end | |
# | |
# Save it. Run the test again. | |
# | |
# ## Watch it fail | |
# | |
# Now you should see an error like this: | |
# | |
# the hello function | |
# says hello (FAILED - 1) | |
# | |
# Failures: | |
# | |
# 1) the hello function says hello | |
# Failure/Error: hello().should == "Hello!" | |
# expected: "Hello!" | |
# got: nil (using ==) | |
# # ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>' | |
# | |
# This means that while it found the file, and it found the function, it's not returning anything! ("nil" is the Ruby way of saying "not anything".) | |
# | |
# ## Make it return something | |
# | |
# Inside the "hello" function, put a single line containing a string that is *not* "Hello!". (Here we are simulating you making an honest mistake, so we can see what the error message looks like.) | |
# | |
# def hello | |
# "whuh?" | |
# end | |
# | |
# Save it. Run the test again. | |
# | |
# ## Watch it fail | |
# | |
# Now you should see an error like this: | |
# | |
# 1) the hello function says hello | |
# Failure/Error: hello().should == "Hello!" | |
# expected: "Hello!" | |
# got: "whuh?" (using ==) | |
# # ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>' | |
# | |
# Correct this by changing "whuh?" to "Hello!". Save it. Run the test again. | |
# | |
# ## Watch it pass! | |
# | |
# Hooray! Finally! It works! | |
# | |
# ## Give yourself a high five | |
# | |
# Also, sing a song and do a little dance. | |
# | |
# ## And then... | |
# | |
# Fix the next failure! `:-)` | |
# | |
# the hello function | |
# says hello | |
# | |
# the greet function | |
# says hello to someone (FAILED - 1) | |
# | |
# In order to get the next test to pass, your function will need to accept an *argument*. | |
# | |
# def greet(who) | |
# "Hello, #{who}!" | |
# end | |
# | |
require_relative "hello" | |
describe "the hello function" do | |
it "says hello" do | |
hello.should == "Hello!" | |
end | |
end | |
describe "the greet function" do | |
it "says hello to someone" do | |
greet("Alice").should == "Hello, Alice!" | |
end | |
it "says hello to someone else" do | |
greet("Bob").should == "Hello, Bob!" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: hello</title> | |
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="../index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li>00 Hello</li> | |
<li><a href="../01_temperature/index.html">01 Temperature</a></li> | |
<li><a href="../02_calculator/index.html">02 Calculator</a></li> | |
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li> | |
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li> | |
<li><a href="../09_timer/index.html">09 Timer</a></li> | |
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li> | |
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li> | |
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li><a href="../15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>hello</h1> | |
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Hello!</h1> | |
<p>This lab teaches basic Ruby function syntax.</p> | |
<h2>Open a terminal in this directory</h2> | |
<pre><code>cd 00_hello | |
</code></pre> | |
<p>This directory is the starting point for this exercise. It contains a spec file and you'll be adding a ruby file to (eventually) make the specs pass.</p> | |
<h2>Run the test</h2> | |
<pre><code>rake | |
</code></pre> | |
<h2>Watch it fail</h2> | |
<p>You should see an error. <strong>Don't get scared!</strong> Try to read it and figure out what the computer wants to tell you. Somewhere on the first line it should say something like</p> | |
<pre><code>no such file to load -- test-first-teaching/hello/hello (LoadError) | |
</code></pre> | |
<p>That means that it is looking for a file called <code>hello.rb</code> and can't find it.</p> | |
<h2>Create hello.rb</h2> | |
<p>Open up <code>hello.rb</code> in a text editor. Save it. Run the test again.</p> | |
<pre><code>rake | |
</code></pre> | |
<h2>Watch it fail</h2> | |
<p>Now you should see an error like this:</p> | |
<pre><code>the hello function | |
says hello (FAILED - 1) | |
Failures: | |
1) the hello function says hello | |
Failure/Error: hello.should == "Hello!" | |
NameError: | |
undefined local variable or method `hello' for #<RSpec::Core::ExampleGroup::Nested_1:0x000001009b8808> | |
# ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>' | |
</code></pre> | |
<h2>Create the hello function</h2> | |
<p>Fix this by opening <code>hello.rb</code> and creating an empty function:</p> | |
<pre><code>def hello | |
end | |
</code></pre> | |
<p>Save it. Run the test again.</p> | |
<h2>Watch it fail</h2> | |
<p>Now you should see an error like this:</p> | |
<pre><code>the hello function | |
says hello (FAILED - 1) | |
Failures: | |
1) the hello function says hello | |
Failure/Error: hello().should == "Hello!" | |
expected: "Hello!" | |
got: nil (using ==) | |
# ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>' | |
</code></pre> | |
<p>This means that while it found the file, and it found the function, it's not returning anything! ("nil" is the Ruby way of saying "not anything".)</p> | |
<h2>Make it return something</h2> | |
<p>Inside the "hello" function, put a single line containing a string that is <em>not</em> "Hello!". (Here we are simulating you making an honest mistake, so we can see what the error message looks like.)</p> | |
<pre><code>def hello | |
"whuh?" | |
end | |
</code></pre> | |
<p>Save it. Run the test again.</p> | |
<h2>Watch it fail</h2> | |
<p>Now you should see an error like this:</p> | |
<pre><code>1) the hello function says hello | |
Failure/Error: hello().should == "Hello!" | |
expected: "Hello!" | |
got: "whuh?" (using ==) | |
# ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>' | |
</code></pre> | |
<p>Correct this by changing "whuh?" to "Hello!". Save it. Run the test again.</p> | |
<h2>Watch it pass!</h2> | |
<p>Hooray! Finally! It works!</p> | |
<h2>Give yourself a high five</h2> | |
<p>Also, sing a song and do a little dance.</p> | |
<h2>And then...</h2> | |
<p>Fix the next failure! <code>:-)</code></p> | |
<pre><code>the hello function | |
says hello | |
the greet function | |
says hello to someone (FAILED - 1) | |
</code></pre> | |
<p>In order to get the next test to pass, your function will need to accept an <em>argument</em>.</p> | |
<pre><code>def greet(who) | |
"Hello, #{who}!" | |
end | |
</code></pre> | |
</div> | |
<div class="tests"> | |
<h1>Tests</h1> | |
<a class="raw_file" href="hello_spec.rb">hello_spec.rb</a> | |
<pre>require "hello" | |
describe "the hello function" do | |
it "says hello" do | |
hello.should == "Hello!" | |
end | |
end | |
describe "the greet function" do | |
it "says hello to someone" do | |
greet("Alice").should == "Hello, Alice!" | |
end | |
it "says hello to someone else" do | |
greet("Bob").should == "Hello, Bob!" | |
end | |
end</pre> | |
</div> | |
</div> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: temperature</title> | |
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="../index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="../00_hello/index.html">00 Hello</a></li> | |
<li>01 Temperature</li> | |
<li><a href="../02_calculator/index.html">02 Calculator</a></li> | |
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li> | |
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li> | |
<li><a href="../09_timer/index.html">09 Timer</a></li> | |
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li> | |
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li> | |
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li><a href="../15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>temperature</h1> | |
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Topics:</h1> | |
<ul> | |
<li>functions</li> | |
<li>floating-point math</li> | |
</ul> | |
<h1>Hints</h1> | |
<p>Remember that one degree fahrenheit is 5/9 of one degree celsius, and that the freezing point of water is 0 degrees celsius but 32 degrees fahrenheit.</p> | |
<p>In integer math, there <strong>are no fractions</strong>. So if you are using integer literals, you will be using integer math, which means, for example...</p> | |
<p> 1 / 2 => 0</p> | |
<p>In floating point math, there <strong>are</strong> fractions. So...</p> | |
<p> 1.0 / 2.0 => 0.5</p> | |
</div> | |
<div class="tests"> | |
<h1>Tests</h1> | |
<a class="raw_file" href="temperature_spec.rb">temperature_spec.rb</a> | |
<pre> | |
require "temperature" | |
describe "temperature conversion functions" do | |
describe "#ftoc" do | |
it "converts freezing temperature" do | |
ftoc(32).should == 0 | |
end | |
it "converts boiling temperature" do | |
ftoc(212).should == 100 | |
end | |
it "converts body temperature" do | |
ftoc(98.6).should == 37 | |
end | |
it "converts arbitrary temperature" do | |
ftoc(68).should == 20 | |
end | |
end | |
describe "#ctof" do | |
it "converts freezing temperature" do | |
ctof(0).should == 32 | |
end | |
it "converts boiling temperature" do | |
ctof(100).should == 212 | |
end | |
it "converts arbitrary temperature" do | |
ctof(20).should == 68 | |
end | |
it "converts body temperature" do | |
ctof(37).should be_within(0.1).of(98.6) | |
# Why do we need to use be_within? | |
# See http://www.ruby-forum.com/topic/169330 | |
# and http://en.wikipedia.org/wiki/IEEE_754-2008 | |
# and http://en.wikipedia.org/wiki/Double_precision_floating-point_format | |
# Also, try "puts 0.5 - 0.4 - 0.1" -- pretty crazy, right? | |
end | |
end | |
end</pre> | |
</div> | |
</div> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ftoc(fdeg) | |
(fdeg - 32) * 5 /9 | |
end | |
def ctof(cdeg) | |
((cdeg * 9.0) / 5) + 32 | |
end | |
puts ctof 37 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Topics: | |
# * functions | |
# * floating-point math | |
# | |
# # Hints | |
# | |
# Remember that one degree fahrenheit is 5/9 of one degree celsius, and that the freezing point of water is 0 degrees celsius but 32 degrees fahrenheit. | |
# | |
# In integer math, there **are no fractions**. So if you are using integer literals, you will be using integer math, which means, for example... | |
# | |
# 1 / 2 => 0 | |
# | |
# In floating point math, there **are** fractions. So... | |
# | |
# 1.0 / 2.0 => 0.5 | |
# | |
require_relative "temperature" | |
describe "temperature conversion functions" do | |
describe "#ftoc" do | |
it "converts freezing temperature" do | |
ftoc(32).should == 0 | |
end | |
it "converts boiling temperature" do | |
ftoc(212).should == 100 | |
end | |
it "converts body temperature" do | |
ftoc(98.6).should == 37 | |
end | |
it "converts arbitrary temperature" do | |
ftoc(68).should == 20 | |
end | |
end | |
describe "#ctof" do | |
it "converts freezing temperature" do | |
ctof(0).should == 32 | |
end | |
it "converts boiling temperature" do | |
ctof(100).should == 212 | |
end | |
it "converts arbitrary temperature" do | |
ctof(20).should == 68 | |
end | |
it "converts body temperature" do | |
ctof(37).should be_within(0.1).of(98.6) | |
# Why do we need to use be_within? | |
# See http://www.ruby-forum.com/topic/169330 | |
# and http://en.wikipedia.org/wiki/IEEE_754-2008 | |
# and http://en.wikipedia.org/wiki/Double_precision_floating-point_format | |
# Also, try "puts 0.5 - 0.4 - 0.1" -- pretty crazy, right? | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add(*n) | |
sum = 0 | |
n.each do |x| | |
sum += x | |
end | |
sum | |
end | |
def subtract(a, b) | |
a-b | |
end | |
def sum(n) | |
s = 0 | |
n.each do |x| | |
s += x | |
end | |
s | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Topics | |
# | |
# * functions | |
# * math | |
# * arrays | |
# * iterating/looping | |
# | |
# # Calculator | |
# | |
# you will build a simple calculator script with the following methods: | |
# | |
# `add` takes two parameters and adds them | |
# | |
# `subtract` takes two parameters and subtracts the second from the first | |
# | |
# `sum` takes an *array* of parameters and adds them all together | |
# | |
# # Warning | |
# | |
# You may not have enough knowledge yet to complete `sum`. You will probably | |
# need to use **loops** (e.g. `while`) or **iterators** (e.g. `each`) to | |
# get the tests to pass. | |
# | |
# # Bonus | |
# | |
# There are also some bonus exercises for when you finish the regular ones. The bonus round will help teach you test-driven *development*, not simply test-guided *learning*. | |
# | |
# Your mission, should you choose to accept it, is to write *tests* for three new methods: | |
# | |
# * `multiply` which multiplies two numbers together | |
# * `power` which raises one number to the power of another number | |
# * `[factorial](http://en.wikipedia.org/wiki/Factorial)` (check Wikipedia if you forgot your high school math). | |
# | |
# | |
require_relative "calculator" | |
describe "add" do | |
it "adds 0 and 0" do | |
add(0,0).should == 0 | |
end | |
it "adds 2 and 2" do | |
add(2,2).should == 4 | |
end | |
it "adds positive numbers" do | |
add(2,6).should == 8 | |
end | |
end | |
describe "subtract" do | |
it "subtracts numbers" do | |
subtract(10,4).should == 6 | |
end | |
end | |
describe "sum" do | |
it "computes the sum of an empty array" do | |
sum([]).should == 0 | |
end | |
it "computes the sum of an array of one number" do | |
sum([7]).should == 7 | |
end | |
it "computes the sum of an array of two numbers" do | |
sum([7,11]).should == 18 | |
end | |
it "computes the sum of an array of many numbers" do | |
sum([1,3,5,7,9]).should == 25 | |
end | |
end | |
# Extra Credit Test-Driving Bonus: | |
# once the above tests pass, | |
# write tests and code for the following: | |
describe "#multiply" do | |
it "multiplies two numbers" | |
it "multiplies several numbers" | |
end | |
describe "#power" do | |
it "raises one number to the power of another number" | |
end | |
# http://en.wikipedia.org/wiki/Factorial | |
describe "#factorial" do | |
it "computes the factorial of 0" | |
it "computes the factorial of 1" | |
it "computes the factorial of 2" | |
it "computes the factorial of 5" | |
it "computes the factorial of 10" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: calculator</title> | |
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="../index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="../00_hello/index.html">00 Hello</a></li> | |
<li><a href="../01_temperature/index.html">01 Temperature</a></li> | |
<li>02 Calculator</li> | |
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li> | |
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li> | |
<li><a href="../09_timer/index.html">09 Timer</a></li> | |
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li> | |
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li> | |
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li><a href="../15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>calculator</h1> | |
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Topics</h1> | |
<ul> | |
<li>functions</li> | |
<li>math</li> | |
<li>arrays</li> | |
<li>iterating/looping</li> | |
</ul> | |
<h1>Calculator</h1> | |
<p>you will build a simple calculator script with the following methods:</p> | |
<p><code>add</code> takes two parameters and adds them</p> | |
<p><code>subtract</code> takes two parameters and subtracts the second from the first</p> | |
<p><code>sum</code> takes an <em>array</em> of parameters and adds them all together</p> | |
<h1>Warning</h1> | |
<p>You may not have enough knowledge yet to complete <code>sum</code>. You will probably | |
need to use <strong>loops</strong> (e.g. <code>while</code>) or <strong>iterators</strong> (e.g. <code>each</code>) to | |
get the tests to pass.</p> | |
<h1>Bonus</h1> | |
<p>There are also some bonus exercises for when you finish the regular ones. The bonus round will help teach you test-driven <em>development</em>, not simply test-guided <em>learning</em>.</p> | |
<p>Your mission, should you choose to accept it, is to write <em>tests</em> for three new methods:</p> | |
<ul> | |
<li><code>multiply</code> which multiplies two numbers together</li> | |
<li><code>power</code> which raises one number to the power of another number</li> | |
<li><code>[factorial](http://en.wikipedia.org/wiki/Factorial)</code> (check Wikipedia if you forgot your high school math).</li> | |
</ul> | |
</div> | |
<div class="tests"> | |
<h1>Tests</h1> | |
<a class="raw_file" href="calculator_spec.rb">calculator_spec.rb</a> | |
<pre> | |
require "calculator" | |
describe "add" do | |
it "adds 0 and 0" do | |
add(0,0).should == 0 | |
end | |
it "adds 2 and 2" do | |
add(2,2).should == 4 | |
end | |
it "adds positive numbers" do | |
add(2,6).should == 8 | |
end | |
end | |
describe "subtract" do | |
it "subtracts numbers" do | |
subtract(10,4).should == 6 | |
end | |
end | |
describe "sum" do | |
it "computes the sum of an empty array" do | |
sum([]).should == 0 | |
end | |
it "computes the sum of an array of one number" do | |
sum([7]).should == 7 | |
end | |
it "computes the sum of an array of two numbers" do | |
sum([7,11]).should == 18 | |
end | |
it "computes the sum of an array of many numbers" do | |
sum([1,3,5,7,9]).should == 25 | |
end | |
end | |
# Extra Credit Test-Driving Bonus: | |
# once the above tests pass, | |
# write tests and code for the following: | |
describe "#multiply" do | |
it "multiplies two numbers" | |
it "multiplies several numbers" | |
end | |
describe "#power" do | |
it "raises one number to the power of another number" | |
end | |
# http://en.wikipedia.org/wiki/Factorial | |
describe "#factorial" do | |
it "computes the factorial of 0" | |
it "computes the factorial of 1" | |
it "computes the factorial of 2" | |
it "computes the factorial of 5" | |
it "computes the factorial of 10" | |
end</pre> | |
</div> | |
</div> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: simon_says</title> | |
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="../index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="../00_hello/index.html">00 Hello</a></li> | |
<li><a href="../01_temperature/index.html">01 Temperature</a></li> | |
<li><a href="../02_calculator/index.html">02 Calculator</a></li> | |
<li>03 Simon Says</li> | |
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li> | |
<li><a href="../09_timer/index.html">09 Timer</a></li> | |
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li> | |
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li> | |
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li><a href="../15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>simon_says</h1> | |
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Simon Says</h1> | |
<h2>Topics</h2> | |
<ul> | |
<li>functions</li> | |
<li>strings</li> | |
<li>default parameter values</li> | |
</ul> | |
<h2>Hints</h2> | |
<p>When you make the second <code>repeat</code> test pass, you might break the <strong>first</strong></p> | |
</div> | |
<div class="tests"> | |
<h1>Tests</h1> | |
<a class="raw_file" href="simon_says_spec.rb">simon_says_spec.rb</a> | |
<pre> | |
require "simon_says" | |
describe "Simon says" do | |
describe "echo" do | |
it "should echo hello" do | |
echo("hello").should == "hello" | |
end | |
it "should echo bye" do | |
echo("bye").should == "bye" | |
end | |
end | |
describe "shout" do | |
it "should shout hello" do | |
shout("hello").should == "HELLO" | |
end | |
it "should shout multiple words" do | |
shout("hello world").should == "HELLO WORLD" | |
end | |
end | |
describe "repeat" do | |
it "should repeat" do | |
repeat("hello").should == "hello hello" | |
end | |
# Wait a second! How can you make the "repeat" method | |
# take one *or* two arguments? | |
# | |
# Hint: *default values* | |
it "should repeat a number of times" do | |
repeat("hello", 3).should == "hello hello hello" | |
end | |
end | |
describe "start_of_word" do | |
it "returns the first letter" do | |
start_of_word("hello", 1).should == "h" | |
end | |
it "returns the first two letters" do | |
start_of_word("Bob", 2).should == "Bo" | |
end | |
it "returns the first several letters" do | |
s = "abcdefg" | |
start_of_word(s, 1).should == "a" | |
start_of_word(s, 2).should == "ab" | |
start_of_word(s, 3).should == "abc" | |
end | |
end | |
describe "first_word" do | |
it "tells us the first word of 'Hello World' is 'Hello'" do | |
first_word("Hello World").should == "Hello" | |
end | |
it "tells us the first word of 'oh dear' is 'oh'" do | |
first_word("oh dear").should == "oh" | |
end | |
end | |
describe "titleize" do | |
it "capitalizes a word" do | |
titleize("jaws").should == "Jaws" | |
end | |
it "capitalizes every word (aka title case)" do | |
titleize("david copperfield").should == "David Copperfield" | |
end | |
it "doesn't capitalize 'little words' in a title" do | |
titleize("war and peace").should == "War and Peace" | |
end | |
it "does capitalize 'little words' at the start of a title" do | |
titleize("the bridge over the river kwai").should == "The Bridge over the River Kwai" | |
end | |
end | |
end</pre> | |
</div> | |
</div> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def echo(x) | |
x | |
end | |
def shout(x) | |
x.upcase | |
end | |
def repeat(x, y=1) | |
i=1 | |
s=x | |
begin | |
s += " #{x}" | |
i+=1 | |
end while i<y | |
s | |
end | |
def start_of_word(word, nr) | |
s = '' | |
i=0 | |
while i< nr do | |
s+= word[i] | |
i+=1 | |
end | |
s | |
end | |
def first_word(word) | |
a =word.split(' ') | |
a[0].to_s | |
end | |
def titleize(s) | |
words = s.split.map do |word| | |
if %w(the and over).include?(word) | |
word | |
else | |
word.capitalize | |
end | |
end | |
words.first.capitalize! | |
words.join(" ") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Simon Says | |
# | |
# ## Topics | |
# | |
# * functions | |
# * strings | |
# * default parameter values | |
# | |
# ## Hints | |
# | |
# When you make the second `repeat` test pass, you might break the **first** | |
# | |
require_relative "simon_says" | |
describe "Simon says" do | |
describe "echo" do | |
it "should echo hello" do | |
echo("hello").should == "hello" | |
end | |
it "should echo bye" do | |
echo("bye").should == "bye" | |
end | |
end | |
describe "shout" do | |
it "should shout hello" do | |
shout("hello").should == "HELLO" | |
end | |
it "should shout multiple words" do | |
shout("hello world").should == "HELLO WORLD" | |
end | |
end | |
describe "repeat" do | |
it "should repeat" do | |
repeat("hello").should == "hello hello" | |
end | |
# Wait a second! How can you make the "repeat" method | |
# take one *or* two arguments? | |
# | |
# Hint: *default values* | |
it "should repeat a number of times" do | |
repeat("hello", 3).should == "hello hello hello" | |
end | |
end | |
describe "start_of_word" do | |
it "returns the first letter" do | |
start_of_word("hello", 1).should == "h" | |
end | |
it "returns the first two letters" do | |
start_of_word("Bob", 2).should == "Bo" | |
end | |
it "returns the first several letters" do | |
s = "abcdefg" | |
start_of_word(s, 1).should == "a" | |
start_of_word(s, 2).should == "ab" | |
start_of_word(s, 3).should == "abc" | |
end | |
end | |
describe "first_word" do | |
it "tells us the first word of 'Hello World' is 'Hello'" do | |
first_word("Hello World").should == "Hello" | |
end | |
it "tells us the first word of 'oh dear' is 'oh'" do | |
first_word("oh dear").should == "oh" | |
end | |
end | |
describe "titleize" do | |
it "capitalizes a word" do | |
titleize("jaws").should == "Jaws" | |
end | |
it "capitalizes every word (aka title case)" do | |
titleize("david copperfield").should == "David Copperfield" | |
end | |
it "doesn't capitalize 'little words' in a title" do | |
titleize("war and peace").should == "War and Peace" | |
end | |
it "does capitalize 'little words' at the start of a title" do | |
titleize("the bridge over the river kwai").should == "The Bridge over the River Kwai" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: pig_latin</title> | |
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="../index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="../00_hello/index.html">00 Hello</a></li> | |
<li><a href="../01_temperature/index.html">01 Temperature</a></li> | |
<li><a href="../02_calculator/index.html">02 Calculator</a></li> | |
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li> | |
<li>04 Pig Latin</li> | |
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li> | |
<li><a href="../09_timer/index.html">09 Timer</a></li> | |
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li> | |
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li> | |
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li><a href="../15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>pig_latin</h1> | |
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Topics</h1> | |
<ul> | |
<li>modules</li> | |
<li>strings</li> | |
</ul> | |
<h1>Pig Latin</h1> | |
<p>Pig Latin is a made-up children's language that's intended to be confusing. It obeys a few simple rules (below) but when it's spoken quickly it's really difficult for non-children (and non-native speakers) to understand.</p> | |
<p>Rule 1: If a word begins with a vowel sound, add an "ay" sound to the end of the word.</p> | |
<p>Rule 2: If a word begins with a consonant sound, move it to the end of the word, and then add an "ay" sound to the end of the word.</p> | |
<p>(There are a few more rules for edge cases, and there are regional variants too, but that should be enough to understand the tests.)</p> | |
<p>See <a href="http://en.wikipedia.org/wiki/Pig_latin">http://en.wikipedia.org/wiki/Pig_latin</a> for more details.</p> | |
</div> | |
<div class="tests"> | |
<h1>Tests</h1> | |
<a class="raw_file" href="pig_latin_spec.rb">pig_latin_spec.rb</a> | |
<pre> | |
require "pig_latin" | |
describe "#translate" do | |
it "translates a word beginning with a vowel" do | |
s = translate("apple") | |
s.should == "appleay" | |
end | |
it "translates a word beginning with a consonant" do | |
s = translate("banana") | |
s.should == "ananabay" | |
end | |
it "translates a word beginning with two consonants" do | |
s = translate("cherry") | |
s.should == "errychay" | |
end | |
it "translates two words" do | |
s = translate("eat pie") | |
s.should == "eatay iepay" | |
end | |
it "translates a word beginning with three consonants" do | |
translate("three").should == "eethray" | |
end | |
it "counts 'sch' as a single phoneme" do | |
s = translate("school") | |
s.should == "oolschay" | |
end | |
it "counts 'qu' as a single phoneme" do | |
s = translate("quiet") | |
s.should == "ietquay" | |
end | |
it "counts 'qu' as a consonant even when it's preceded by a consonant" do | |
s = translate("square") | |
s.should == "aresquay" | |
end | |
it "translates many words" do | |
s = translate("the quick brown fox") | |
s.should == "ethay ickquay ownbray oxfay" | |
end | |
# Test-driving bonus: | |
# * write a test asserting that capitalized words are still capitalized (but with a different initial capital letter, of course) | |
# * retain the punctuation from the original phrase | |
end</pre> | |
</div> | |
</div> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def vowel? c | |
vowels = ['a','e','i','o','u','y'] | |
vowels.include? c | |
end | |
def translate(s) | |
s.split.map do |word| | |
i = 0 | |
while not vowel? word[i,1] | |
if ( word[i,2] == 'qu') | |
i += 2 | |
else | |
i += 1 | |
end | |
end | |
word[i..-1] + word[0,i] + 'ay' | |
end.join(' ') | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Topics | |
# | |
# * modules | |
# * strings | |
# | |
# # Pig Latin | |
# | |
# Pig Latin is a made-up children's language that's intended to be confusing. It obeys a few simple rules (below) but when it's spoken quickly it's really difficult for non-children (and non-native speakers) to understand. | |
# | |
# Rule 1: If a word begins with a vowel sound, add an "ay" sound to the end of the word. | |
# | |
# Rule 2: If a word begins with a consonant sound, move it to the end of the word, and then add an "ay" sound to the end of the word. | |
# | |
# (There are a few more rules for edge cases, and there are regional variants too, but that should be enough to understand the tests.) | |
# | |
# See <http://en.wikipedia.org/wiki/Pig_latin> for more details. | |
# | |
# | |
require_relative "pig_latin" | |
describe "#translate" do | |
it "translates a word beginning with a vowel" do | |
s = translate("apple") | |
s.should == "appleay" | |
end | |
it "translates a word beginning with a consonant" do | |
s = translate("banana") | |
s.should == "ananabay" | |
end | |
it "translates a word beginning with two consonants" do | |
s = translate("cherry") | |
s.should == "errychay" | |
end | |
it "translates two words" do | |
s = translate("eat pie") | |
s.should == "eatay iepay" | |
end | |
it "translates a word beginning with three consonants" do | |
translate("three").should == "eethray" | |
end | |
it "counts 'sch' as a single phoneme" do | |
s = translate("school") | |
s.should == "oolschay" | |
end | |
it "counts 'qu' as a single phoneme" do | |
s = translate("quiet") | |
s.should == "ietquay" | |
end | |
it "counts 'qu' as a consonant even when it's preceded by a consonant" do | |
s = translate("square") | |
s.should == "aresquay" | |
end | |
it "translates many words" do | |
s = translate("the quick brown fox") | |
s.should == "ethay ickquay ownbray oxfay" | |
end | |
# Test-driving bonus: | |
# * write a test asserting that capitalized words are still capitalized (but with a different initial capital letter, of course) | |
# * retain the punctuation from the original phrase | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: silly_blocks</title> | |
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="../index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="../00_hello/index.html">00 Hello</a></li> | |
<li><a href="../01_temperature/index.html">01 Temperature</a></li> | |
<li><a href="../02_calculator/index.html">02 Calculator</a></li> | |
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li> | |
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li>05 Silly Blocks</li> | |
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li> | |
<li><a href="../09_timer/index.html">09 Timer</a></li> | |
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li> | |
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li> | |
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li><a href="../15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>silly_blocks</h1> | |
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Topics</h1> | |
<ul> | |
<li>blocks</li> | |
<li>closures</li> | |
<li>yield</li> | |
<li>loops</li> | |
</ul> | |
</div> | |
<div class="tests"> | |
<h1>Tests</h1> | |
<a class="raw_file" href="silly_blocks_spec.rb">silly_blocks_spec.rb</a> | |
<pre> | |
require "silly_blocks" | |
describe "some silly block functions" do | |
describe "reverser" do | |
it "reverses the string returned by the default block" do | |
result = reverser do | |
"hello" | |
end | |
result.should == "olleh" | |
end | |
it "reverses each word in the string returned by the default block" do | |
result = reverser do | |
"hello dolly" | |
end | |
result.should == "olleh yllod" | |
end | |
end | |
describe "adder" do | |
it "adds one to the value returned by the default block" do | |
adder do | |
5 | |
end.should == 6 | |
end | |
it "adds 3 to the value returned by the default block" do | |
adder(3) do | |
5 | |
end.should == 8 | |
end | |
end | |
describe "repeater" do | |
it "executes the default block" do | |
block_was_executed = false | |
repeater do | |
block_was_executed = true | |
end | |
block_was_executed.should == true | |
end | |
it "executes the default block 3 times" do | |
n = 0 | |
repeater(3) do | |
n += 1 | |
end | |
n.should == 3 | |
end | |
it "executes the default block 10 times" do | |
n = 0 | |
repeater(10) do | |
n += 1 | |
end | |
n.should == 10 | |
end | |
end | |
end</pre> | |
</div> | |
</div> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Topics | |
# | |
# * blocks | |
# * closures | |
# * yield | |
# * loops | |
# | |
require "silly_blocks" | |
describe "some silly block functions" do | |
describe "reverser" do | |
it "reverses the string returned by the default block" do | |
result = reverser do | |
"hello" | |
end | |
result.should == "olleh" | |
end | |
it "reverses each word in the string returned by the default block" do | |
result = reverser do | |
"hello dolly" | |
end | |
result.should == "olleh yllod" | |
end | |
end | |
describe "adder" do | |
it "adds one to the value returned by the default block" do | |
adder do | |
5 | |
end.should == 6 | |
end | |
it "adds 3 to the value returned by the default block" do | |
adder(3) do | |
5 | |
end.should == 8 | |
end | |
end | |
describe "repeater" do | |
it "executes the default block" do | |
block_was_executed = false | |
repeater do | |
block_was_executed = true | |
end | |
block_was_executed.should == true | |
end | |
it "executes the default block 3 times" do | |
n = 0 | |
repeater(3) do | |
n += 1 | |
end | |
n.should == 3 | |
end | |
it "executes the default block 10 times" do | |
n = 0 | |
repeater(10) do | |
n += 1 | |
end | |
n.should == 10 | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: performance_monitor</title> | |
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="../index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="../00_hello/index.html">00 Hello</a></li> | |
<li><a href="../01_temperature/index.html">01 Temperature</a></li> | |
<li><a href="../02_calculator/index.html">02 Calculator</a></li> | |
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li> | |
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li>06 Performance Monitor</li> | |
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li> | |
<li><a href="../09_timer/index.html">09 Timer</a></li> | |
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li> | |
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li> | |
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li><a href="../15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>performance_monitor</h1> | |
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Topics</h1> | |
<ul> | |
<li>stubs</li> | |
<li>blocks</li> | |
<li>yield</li> | |
</ul> | |
<h1>Performance Monitor</h1> | |
<p>This is (a stripped down version of) an actual useful concept: a function that runs a block of code and then tells you how long it took to run.</p> | |
</div> | |
<div class="tests"> | |
<h1>Tests</h1> | |
<a class="raw_file" href="performance_monitor_spec.rb">performance_monitor_spec.rb</a> | |
<pre> | |
require "performance_monitor" | |
require "time" # loads up the Time.parse method -- do NOT create time.rb! | |
describe "Performance Monitor" do | |
before do | |
@eleven_am = Time.parse("2011-1-2 11:00:00") | |
end | |
it "takes about 0 seconds to run an empty block" do | |
elapsed_time = measure do | |
end | |
elapsed_time.should be_within(0.1).of(0) | |
end | |
it "takes exactly 0 seconds to run an empty block (with stubs)" do | |
Time.stub(:now) { @eleven_am } | |
elapsed_time = measure do | |
end | |
elapsed_time.should == 0 | |
end | |
it "takes about 1 second to run a block that sleeps for 1 second" do | |
elapsed_time = measure do | |
sleep 1 | |
end | |
elapsed_time.should be_within(0.1).of(1) | |
end | |
it "takes exactly 1 second to run a block that sleeps for 1 second (with stubs)" do | |
fake_time = @eleven_am | |
Time.stub(:now) { fake_time } | |
elapsed_time = measure do | |
fake_time += 60 # adds one minute to fake_time | |
end | |
elapsed_time.should == 60 | |
end | |
it "runs a block N times" do | |
n = 0 | |
measure(4) do | |
n += 1 | |
end | |
n.should == 4 | |
end | |
it "returns the average time, not the total time, when running multiple times" do | |
run_times = [8,6,5,7] | |
fake_time = @eleven_am | |
Time.stub(:now) { fake_time } | |
average_time = measure(4) do | |
fake_time += run_times.pop | |
end | |
average_time.should == 6.5 | |
end | |
it "returns the average time when running a random number of times for random lengths of time" do | |
fake_time = @eleven_am | |
Time.stub(:now) { fake_time } | |
number_of_times = rand(10) + 2 | |
average_time = measure(number_of_times) do | |
delay = rand(10) | |
fake_time += delay | |
end | |
average_time.should == (fake_time - @eleven_am).to_f/number_of_times | |
end | |
end</pre> | |
</div> | |
</div> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Topics | |
# | |
# * stubs | |
# * blocks | |
# * yield | |
# | |
# # Performance Monitor | |
# | |
# This is (a stripped down version of) an actual useful concept: a function that runs a block of code and then tells you how long it took to run. | |
require "performance_monitor" | |
require "time" # loads up the Time.parse method -- do NOT create time.rb! | |
describe "Performance Monitor" do | |
before do | |
@eleven_am = Time.parse("2011-1-2 11:00:00") | |
end | |
it "takes about 0 seconds to run an empty block" do | |
elapsed_time = measure do | |
end | |
elapsed_time.should be_within(0.1).of(0) | |
end | |
it "takes exactly 0 seconds to run an empty block (with stubs)" do | |
Time.stub(:now) { @eleven_am } | |
elapsed_time = measure do | |
end | |
elapsed_time.should == 0 | |
end | |
it "takes about 1 second to run a block that sleeps for 1 second" do | |
elapsed_time = measure do | |
sleep 1 | |
end | |
elapsed_time.should be_within(0.1).of(1) | |
end | |
it "takes exactly 1 second to run a block that sleeps for 1 second (with stubs)" do | |
fake_time = @eleven_am | |
Time.stub(:now) { fake_time } | |
elapsed_time = measure do | |
fake_time += 60 # adds one minute to fake_time | |
end | |
elapsed_time.should == 60 | |
end | |
it "runs a block N times" do | |
n = 0 | |
measure(4) do | |
n += 1 | |
end | |
n.should == 4 | |
end | |
it "returns the average time, not the total time, when running multiple times" do | |
run_times = [8,6,5,7] | |
fake_time = @eleven_am | |
Time.stub(:now) { fake_time } | |
average_time = measure(4) do | |
fake_time += run_times.pop | |
end | |
average_time.should == 6.5 | |
end | |
it "returns the average time when running a random number of times for random lengths of time" do | |
fake_time = @eleven_am | |
Time.stub(:now) { fake_time } | |
number_of_times = rand(10) + 2 | |
average_time = measure(number_of_times) do | |
delay = rand(10) | |
fake_time += delay | |
end | |
average_time.should == (fake_time - @eleven_am).to_f/number_of_times | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Hello, friend! | |
# | |
# This lab teaches basic Ruby Object syntax. | |
# | |
# ## Watch it fail | |
# | |
# Your first real failure should be something like this: | |
# | |
# ./friend_spec.rb:3: uninitialized constant Friend (NameError) | |
# | |
# Fix this by opening `friend.rb` and creating an empty class: | |
# | |
# class Friend | |
# end | |
# | |
# Save it. Run the test again. | |
# | |
# ## Watch it fail again | |
# | |
# Now you should see an error like this: | |
# | |
# NoMethodError in 'Friend says hello' | |
# undefined method `greeting' for #<Friend:0x1180f3c> | |
# ./friend_spec.rb:5: | |
# | |
# This means that while it found the file, and it found the class, it couldn't find the method named "greeting". | |
# | |
# ## Define the "greeting" method | |
# | |
# In `friend.rb`, add the following inside the class (before the "end"). | |
# | |
# def greeting | |
# end | |
# | |
# Save it. Run the test again. | |
# | |
# ## Watch it fail some more | |
# | |
# Now you should see an error like this: | |
# | |
# 'Friend says hello' FAILED | |
# expected: "Hello!", | |
# got: nil (using ==) | |
# ./friend_spec.rb:5: | |
# | |
# This means that there is a method, but it's not returning anything! ("nil" is the Ruby way of saying "not anything".) | |
# | |
# ## Make it return something | |
# | |
# Inside the "greeting" method, put a single line containing a string that is *not* "Hello!". (Here we are simulating you making an honest mistake, so we can see what the error message looks like.) | |
# | |
# def greeting | |
# "whuh?" | |
# end | |
# | |
# Save it. Run the test again. | |
# | |
# ## Watch it fail yet again | |
# | |
# Now you should see an error like this: | |
# | |
# 'Friend says hello' FAILED | |
# expected: "Hello!", | |
# got: "whuh?" (using ==) | |
# ./friend_spec.rb:5: | |
# | |
# Correct this by changing "whuh?" to "Hello!". Save it. Run the test again. | |
# | |
# ## Watch it pass! | |
# | |
# Hooray! Finally! It works! | |
# | |
# ## Give yourself a high five | |
# | |
# Also, sing a song and do a little dance. | |
# | |
# ## And then... | |
# | |
# Fix the next failure! :-) | |
# | |
# Hint 1: in order to get the next test to pass, you will need to pass a *parameter*: | |
# | |
# def greeting(who) | |
# | |
# Hint 2: once you do that, the **first** test might start failing again. To fix both at the same time, you need to provide a **default value** for that parameter: | |
# | |
# def greeting(who = nil) | |
# | |
# | |
require "friend" | |
describe Friend do | |
it "says hello" do | |
Friend.new.greeting.should == "Hello!" | |
end | |
it "says hello to someone" do | |
Friend.new.greeting("Bob").should == "Hello, Bob!" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: hello_friend</title> | |
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="../index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="../00_hello/index.html">00 Hello</a></li> | |
<li><a href="../01_temperature/index.html">01 Temperature</a></li> | |
<li><a href="../02_calculator/index.html">02 Calculator</a></li> | |
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li> | |
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li>07 Hello Friend</li> | |
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li> | |
<li><a href="../09_timer/index.html">09 Timer</a></li> | |
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li> | |
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li> | |
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li><a href="../15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>hello_friend</h1> | |
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Hello, friend!</h1> | |
<p>This lab teaches basic Ruby Object syntax.</p> | |
<h2>Watch it fail</h2> | |
<p>Your first real failure should be something like this:</p> | |
<pre><code>./friend_spec.rb:3: uninitialized constant Friend (NameError) | |
</code></pre> | |
<p>Fix this by opening <code>friend.rb</code> and creating an empty class:</p> | |
<pre><code>class Friend | |
end | |
</code></pre> | |
<p>Save it. Run the test again.</p> | |
<h2>Watch it fail again</h2> | |
<p>Now you should see an error like this:</p> | |
<pre><code>NoMethodError in 'Friend says hello' | |
undefined method `greeting' for #<Friend:0x1180f3c> | |
./friend_spec.rb:5: | |
</code></pre> | |
<p>This means that while it found the file, and it found the class, it couldn't find the method named "greeting".</p> | |
<h2>Define the "greeting" method</h2> | |
<p>In <code>friend.rb</code>, add the following inside the class (before the "end").</p> | |
<pre><code>def greeting | |
end | |
</code></pre> | |
<p>Save it. Run the test again.</p> | |
<h2>Watch it fail some more</h2> | |
<p>Now you should see an error like this:</p> | |
<pre><code>'Friend says hello' FAILED | |
expected: "Hello!", | |
got: nil (using ==) | |
./friend_spec.rb:5: | |
</code></pre> | |
<p>This means that there is a method, but it's not returning anything! ("nil" is the Ruby way of saying "not anything".)</p> | |
<h2>Make it return something</h2> | |
<p>Inside the "greeting" method, put a single line containing a string that is <em>not</em> "Hello!". (Here we are simulating you making an honest mistake, so we can see what the error message looks like.)</p> | |
<pre><code>def greeting | |
"whuh?" | |
end | |
</code></pre> | |
<p>Save it. Run the test again.</p> | |
<h2>Watch it fail yet again</h2> | |
<p>Now you should see an error like this:</p> | |
<pre><code>'Friend says hello' FAILED | |
expected: "Hello!", | |
got: "whuh?" (using ==) | |
./friend_spec.rb:5: | |
</code></pre> | |
<p>Correct this by changing "whuh?" to "Hello!". Save it. Run the test again.</p> | |
<h2>Watch it pass!</h2> | |
<p>Hooray! Finally! It works!</p> | |
<h2>Give yourself a high five</h2> | |
<p>Also, sing a song and do a little dance.</p> | |
<h2>And then...</h2> | |
<p>Fix the next failure! :-)</p> | |
<p>Hint 1: in order to get the next test to pass, you will need to pass a <em>parameter</em>:</p> | |
<pre><code>def greeting(who) | |
</code></pre> | |
<p>Hint 2: once you do that, the <strong>first</strong> test might start failing again. To fix both at the same time, you need to provide a <strong>default value</strong> for that parameter:</p> | |
<pre><code>def greeting(who = nil) | |
</code></pre> | |
</div> | |
<div class="tests"> | |
<h1>Tests</h1> | |
<a class="raw_file" href="hello_friend_spec.rb">hello_friend_spec.rb</a> | |
<pre> | |
require "friend" | |
describe Friend do | |
it "says hello" do | |
Friend.new.greeting.should == "Hello!" | |
end | |
it "says hello to someone" do | |
Friend.new.greeting("Bob").should == "Hello, Bob!" | |
end | |
end</pre> | |
</div> | |
</div> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Book | |
attr_reader :title | |
def title=(new_title) | |
words = new_title.split(" ") | |
words = [words[0].capitalize] + | |
words[1..-1].map do |word| | |
little_words = %w{a an and the in of} | |
if little_words.include? word | |
word | |
else | |
word.capitalize | |
end | |
end | |
@title = words.join(" ") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Book Titles | |
# | |
# # Topics | |
# | |
# * classes and objects | |
# * instance variables | |
# * setter methods | |
# * strings | |
# | |
# # Notes | |
# | |
# Book Titles in English obey some strange capitalization rules. For example, "and" is lowercase in "War and Peace". This test attempts to make sense of some of those rules. | |
# | |
require_relative 'book' | |
describe Book do | |
before do | |
@book = Book.new | |
end | |
describe 'title' do | |
it 'should capitalize the first letter' do | |
@book.title = "inferno" | |
@book.title.should == "Inferno" | |
end | |
it 'should capitalize every word' do | |
@book.title = "stuart little" | |
@book.title.should == "Stuart Little" | |
end | |
describe 'should capitalize every word except...' do | |
describe 'articles' do | |
specify 'the' do | |
@book.title = "alexander the great" | |
@book.title.should == "Alexander the Great" | |
end | |
specify 'a' do | |
@book.title = "to kill a mockingbird" | |
@book.title.should == "To Kill a Mockingbird" | |
end | |
specify 'an' do | |
@book.title = "to eat an apple a day" | |
@book.title.should == "To Eat an Apple a Day" | |
end | |
end | |
specify 'conjunctions' do | |
@book.title = "war and peace" | |
@book.title.should == "War and Peace" | |
end | |
specify 'prepositions' do | |
@book.title = "love in the time of cholera" | |
@book.title.should == "Love in the Time of Cholera" | |
end | |
end | |
describe 'should always capitalize...' do | |
specify 'I' do | |
@book.title = "what i wish i knew when i was 20" | |
@book.title.should == "What I Wish I Knew When I Was 20" | |
end | |
specify 'the first word' do | |
@book.title = "the man in the iron mask" | |
@book.title.should == "The Man in the Iron Mask" | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: book_titles</title> | |
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="../index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="../00_hello/index.html">00 Hello</a></li> | |
<li><a href="../01_temperature/index.html">01 Temperature</a></li> | |
<li><a href="../02_calculator/index.html">02 Calculator</a></li> | |
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li> | |
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li>08 Book Titles</li> | |
<li><a href="../09_timer/index.html">09 Timer</a></li> | |
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li> | |
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li> | |
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li><a href="../15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>book_titles</h1> | |
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Book Titles</h1> | |
<h1>Topics</h1> | |
<ul> | |
<li>classes and objects</li> | |
<li>instance variables</li> | |
<li>setter methods</li> | |
<li>strings</li> | |
</ul> | |
<h1>Notes</h1> | |
<p>Book Titles in English obey some strange capitalization rules. For example, "and" is lowercase in "War and Peace". This test attempts to make sense of some of those rules.</p> | |
</div> | |
<div class="tests"> | |
<h1>Tests</h1> | |
<a class="raw_file" href="book_titles_spec.rb">book_titles_spec.rb</a> | |
<pre> | |
require 'book' | |
describe Book do | |
before do | |
@book = Book.new | |
end | |
describe 'title' do | |
it 'should capitalize the first letter' do | |
@book.title = "inferno" | |
@book.title.should == "Inferno" | |
end | |
it 'should capitalize every word' do | |
@book.title = "stuart little" | |
@book.title.should == "Stuart Little" | |
end | |
describe 'should capitalize every word except...' do | |
describe 'articles' do | |
specify 'the' do | |
@book.title = "alexander the great" | |
@book.title.should == "Alexander the Great" | |
end | |
specify 'a' do | |
@book.title = "to kill a mockingbird" | |
@book.title.should == "To Kill a Mockingbird" | |
end | |
specify 'an' do | |
@book.title = "to eat an apple a day" | |
@book.title.should == "To Eat an Apple a Day" | |
end | |
end | |
specify 'conjunctions' do | |
@book.title = "war and peace" | |
@book.title.should == "War and Peace" | |
end | |
specify 'prepositions' do | |
@book.title = "love in the time of cholera" | |
@book.title.should == "Love in the Time of Cholera" | |
end | |
end | |
describe 'should always capitalize...' do | |
specify 'I' do | |
@book.title = "what i wish i knew when i was 20" | |
@book.title.should == "What I Wish I Knew When I Was 20" | |
end | |
specify 'the first word' do | |
@book.title = "the man in the iron mask" | |
@book.title.should == "The Man in the Iron Mask" | |
end | |
end | |
end | |
end</pre> | |
</div> | |
</div> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: timer</title> | |
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="../index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="../00_hello/index.html">00 Hello</a></li> | |
<li><a href="../01_temperature/index.html">01 Temperature</a></li> | |
<li><a href="../02_calculator/index.html">02 Calculator</a></li> | |
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li> | |
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li> | |
<li>09 Timer</li> | |
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li> | |
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li> | |
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li><a href="../15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>timer</h1> | |
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Topics</h1> | |
<ul> | |
<li>classes</li> | |
<li>instance variables</li> | |
<li>string formats</li> | |
<li>modular arithmetic</li> | |
</ul> | |
<h1>Timer</h1> | |
</div> | |
<div class="tests"> | |
<h1>Tests</h1> | |
<a class="raw_file" href="timer_spec.rb">timer_spec.rb</a> | |
<pre> | |
require 'timer' | |
describe "Timer" do | |
before(:each) do | |
@timer = Timer.new | |
end | |
it "should initialize to 0 seconds" do | |
@timer.seconds.should == 0 | |
end | |
describe 'time_string' do | |
it "should display 0 seconds as 00:00:00" do | |
@timer.seconds = 0 | |
@timer.time_string.should == "00:00:00" | |
end | |
it "should display 12 seconds as 00:00:12" do | |
@timer.seconds = 12 | |
@timer.time_string.should == "00:00:12" | |
end | |
it "should display 66 seconds as 00:01:06" do | |
@timer.seconds = 66 | |
@timer.time_string.should == "00:01:06" | |
end | |
it "should display 4000 seconds as 01:06:40" do | |
@timer.seconds = 4000 | |
@timer.time_string.should == "01:06:40" | |
end | |
end | |
# One way to implement the Timer is with a helper method. | |
# Uncomment these specs if you want to test-drive that | |
# method, then call that method from inside of time_string. | |
# | |
# describe 'padded' do | |
# it 'pads zero' do | |
# @timer.padded(0).should == '00' | |
# end | |
# it 'pads one' do | |
# @timer.padded(1).should == '01' | |
# end | |
# it "doesn't pad a two-digit number" do | |
# @timer.padded(12).should == '12' | |
# end | |
# end | |
end</pre> | |
</div> | |
</div> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Timer | |
attr_accessor :seconds | |
def initialize | |
@seconds = 0 | |
end | |
def time_string | |
hours = @seconds/3600 | |
remainder = @seconds%3600 | |
sprintf("%02d:%02d:%02d", hours, remainder/60, remainder%60) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Topics | |
# | |
# * classes | |
# * instance variables | |
# * string formats | |
# * modular arithmetic | |
# | |
# # Timer | |
require_relative 'timer' | |
describe "Timer" do | |
before(:each) do | |
@timer = Timer.new | |
end | |
it "should initialize to 0 seconds" do | |
@timer.seconds.should == 0 | |
end | |
describe 'time_string' do | |
it "should display 0 seconds as 00:00:00" do | |
@timer.seconds = 0 | |
@timer.time_string.should == "00:00:00" | |
end | |
it "should display 12 seconds as 00:00:12" do | |
@timer.seconds = 12 | |
@timer.time_string.should == "00:00:12" | |
end | |
it "should display 66 seconds as 00:01:06" do | |
@timer.seconds = 66 | |
@timer.time_string.should == "00:01:06" | |
end | |
it "should display 4000 seconds as 01:06:40" do | |
@timer.seconds = 4000 | |
@timer.time_string.should == "01:06:40" | |
end | |
end | |
# One way to implement the Timer is with a helper method. | |
# Uncomment these specs if you want to test-drive that | |
# method, then call that method from inside of time_string. | |
# | |
# describe 'padded' do | |
# it 'pads zero' do | |
# @timer.padded(0).should == '00' | |
# end | |
# it 'pads one' do | |
# @timer.padded(1).should == '01' | |
# end | |
# it "doesn't pad a two-digit number" do | |
# @timer.padded(12).should == '12' | |
# end | |
# end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: temperature_object</title> | |
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="../index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="../00_hello/index.html">00 Hello</a></li> | |
<li><a href="../01_temperature/index.html">01 Temperature</a></li> | |
<li><a href="../02_calculator/index.html">02 Calculator</a></li> | |
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li> | |
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li> | |
<li><a href="../09_timer/index.html">09 Timer</a></li> | |
<li>10 Temperature Object</li> | |
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li> | |
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li> | |
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li><a href="../15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>temperature_object</h1> | |
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Topics:</h1> | |
<ul> | |
<li>floating-point math</li> | |
<li>objects</li> | |
<li>constructors</li> | |
<li>class methods</li> | |
<li>factory methods</li> | |
<li>options hashes</li> | |
</ul> | |
<h1>Hints</h1> | |
<p>Remember that one degree fahrenheit is 5/9 of one degree celsius, and that the freezing point of water is 0 degrees celsius but 32 degrees fahrenheit.</p> | |
<p>Remember to define the <code>from_celsius</code> factory method as a <em>class</em> method, not an <em>instance</em> method.</p> | |
<p>The temperature object's constructor should accept an <em>options hash</em> which contains either a <code>:celcius</code> entry or a <code>:fahrenheit</code> entry.</p> | |
</div> | |
<div class="tests"> | |
<h1>Tests</h1> | |
<a class="raw_file" href="temperature_object_spec.rb">temperature_object_spec.rb</a> | |
<pre> | |
require "temperature" | |
describe Temperature do | |
describe "can be constructed with an options hash" do | |
describe "in degrees fahrenheit" do | |
it "at 50 degrees" do | |
Temperature.new(:f => 50).in_fahrenheit.should == 50 | |
end | |
describe "and correctly convert to celsius" do | |
it "at freezing" do | |
Temperature.new(:f => 32).in_celsius.should == 0 | |
end | |
it "at boiling" do | |
Temperature.new(:f => 212).in_celsius.should == 100 | |
end | |
it "at body temperature" do | |
Temperature.new(:f => 98.6).in_celsius.should == 37 | |
end | |
it "at an arbitrary temperature" do | |
Temperature.new(:f => 68).in_celsius.should == 20 | |
end | |
end | |
end | |
describe "in degrees celsius" do | |
it "at 50 degrees" do | |
Temperature.new(:c => 50).in_celsius.should == 50 | |
end | |
describe "and correctly convert to fahrenheit" do | |
it "at freezing" do | |
Temperature.new(:c => 0).in_fahrenheit.should == 32 | |
end | |
it "at boiling" do | |
Temperature.new(:c => 100).in_fahrenheit.should == 212 | |
end | |
it "at body temperature" do | |
Temperature.new(:c => 37).in_fahrenheit.should be_within(0.1).of(98.6) | |
# Why do we need to use be_within here? | |
# See http://www.ruby-forum.com/topic/169330 | |
# and http://groups.google.com/group/rspec/browse_thread/thread/f3ebbe3c313202bb | |
# Also, try "puts 0.5 - 0.4 - 0.1" -- pretty crazy, right? | |
end | |
end | |
end | |
end | |
# Factory Method is a design pattern, not a Ruby language feature. | |
# One way to implement this pattern in Ruby is via class methods -- | |
# that is, methods defined on the class (Temperature) rather than | |
# on individual instances of the class. | |
describe "can be constructed via factory methods" do | |
it "in degrees celsius" do | |
Temperature.from_celsius(50).in_celsius.should == 50 | |
Temperature.from_celsius(50).in_fahrenheit.should == 122 | |
end | |
it "in degrees fahrenheit" do | |
Temperature.from_fahrenheit(50).in_fahrenheit.should == 50 | |
Temperature.from_fahrenheit(50).in_celsius.should == 10 | |
end | |
end | |
# test-driving bonus: | |
# | |
# 1. make two class methods -- ftoc and ctof | |
# 2. refactor to call those methods from the rest of the object | |
# | |
# run *all* the tests during your refactoring, to make sure you did it right | |
# | |
describe "utility class methods" do | |
end | |
# Here's another way to solve the problem! | |
describe "Temperature subclasses" do | |
describe "Celsius subclass" do | |
it "is constructed in degrees celsius" do | |
Celsius.new(50).in_celsius.should == 50 | |
Celsius.new(50).in_fahrenheit.should == 122 | |
end | |
it "is a Temperature subclass" do | |
Celsius.new(0).should be_a(Temperature) | |
end | |
end | |
describe "Fahrenheit subclass" do | |
it "is constructed in degrees fahrenheit" do | |
Fahrenheit.new(50).in_fahrenheit.should == 50 | |
Fahrenheit.new(50).in_celsius.should == 10 | |
end | |
it "is a Temperature subclass" do | |
Fahrenheit.new(0).should be_a(Temperature) | |
end | |
end | |
end | |
end</pre> | |
</div> | |
</div> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Topics: | |
# * floating-point math | |
# * objects | |
# * constructors | |
# * class methods | |
# * factory methods | |
# * options hashes | |
# | |
# # Hints | |
# | |
# Remember that one degree fahrenheit is 5/9 of one degree celsius, and that the freezing point of water is 0 degrees celsius but 32 degrees fahrenheit. | |
# | |
# Remember to define the `from_celsius` factory method as a *class* method, not an *instance* method. | |
# | |
# The temperature object's constructor should accept an *options hash* which contains either a `:celcius` entry or a `:fahrenheit` entry. | |
# | |
# | |
# | |
require "temperature" | |
describe Temperature do | |
describe "can be constructed with an options hash" do | |
describe "in degrees fahrenheit" do | |
it "at 50 degrees" do | |
Temperature.new(:f => 50).in_fahrenheit.should == 50 | |
end | |
describe "and correctly convert to celsius" do | |
it "at freezing" do | |
Temperature.new(:f => 32).in_celsius.should == 0 | |
end | |
it "at boiling" do | |
Temperature.new(:f => 212).in_celsius.should == 100 | |
end | |
it "at body temperature" do | |
Temperature.new(:f => 98.6).in_celsius.should == 37 | |
end | |
it "at an arbitrary temperature" do | |
Temperature.new(:f => 68).in_celsius.should == 20 | |
end | |
end | |
end | |
describe "in degrees celsius" do | |
it "at 50 degrees" do | |
Temperature.new(:c => 50).in_celsius.should == 50 | |
end | |
describe "and correctly convert to fahrenheit" do | |
it "at freezing" do | |
Temperature.new(:c => 0).in_fahrenheit.should == 32 | |
end | |
it "at boiling" do | |
Temperature.new(:c => 100).in_fahrenheit.should == 212 | |
end | |
it "at body temperature" do | |
Temperature.new(:c => 37).in_fahrenheit.should be_within(0.1).of(98.6) | |
# Why do we need to use be_within here? | |
# See http://www.ruby-forum.com/topic/169330 | |
# and http://groups.google.com/group/rspec/browse_thread/thread/f3ebbe3c313202bb | |
# Also, try "puts 0.5 - 0.4 - 0.1" -- pretty crazy, right? | |
end | |
end | |
end | |
end | |
# Factory Method is a design pattern, not a Ruby language feature. | |
# One way to implement this pattern in Ruby is via class methods -- | |
# that is, methods defined on the class (Temperature) rather than | |
# on individual instances of the class. | |
describe "can be constructed via factory methods" do | |
it "in degrees celsius" do | |
Temperature.from_celsius(50).in_celsius.should == 50 | |
Temperature.from_celsius(50).in_fahrenheit.should == 122 | |
end | |
it "in degrees fahrenheit" do | |
Temperature.from_fahrenheit(50).in_fahrenheit.should == 50 | |
Temperature.from_fahrenheit(50).in_celsius.should == 10 | |
end | |
end | |
# test-driving bonus: | |
# | |
# 1. make two class methods -- ftoc and ctof | |
# 2. refactor to call those methods from the rest of the object | |
# | |
# run *all* the tests during your refactoring, to make sure you did it right | |
# | |
describe "utility class methods" do | |
end | |
# Here's another way to solve the problem! | |
describe "Temperature subclasses" do | |
describe "Celsius subclass" do | |
it "is constructed in degrees celsius" do | |
Celsius.new(50).in_celsius.should == 50 | |
Celsius.new(50).in_fahrenheit.should == 122 | |
end | |
it "is a Temperature subclass" do | |
Celsius.new(0).should be_a(Temperature) | |
end | |
end | |
describe "Fahrenheit subclass" do | |
it "is constructed in degrees fahrenheit" do | |
Fahrenheit.new(50).in_fahrenheit.should == 50 | |
Fahrenheit.new(50).in_celsius.should == 10 | |
end | |
it "is a Temperature subclass" do | |
Fahrenheit.new(0).should be_a(Temperature) | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Topics | |
# | |
# * Hash | |
# * Array | |
# * instance variables | |
# * regular expressions | |
# | |
require 'dictionary' | |
describe Dictionary do | |
before do | |
@d = Dictionary.new | |
end | |
it 'is empty when created' do | |
@d.entries.should == {} | |
end | |
it 'can add whole entries with keyword and definition' do | |
@d.add('fish' => 'aquatic animal') | |
@d.entries.should == {'fish' => 'aquatic animal'} | |
@d.keywords.should == ['fish'] | |
end | |
it 'add keywords (without definition)' do | |
@d.add('fish') | |
@d.entries.should == {'fish' => nil} | |
@d.keywords.should == ['fish'] | |
end | |
it 'can check whether a given keyword exists' do | |
@d.include?('fish').should be_false | |
end | |
it "doesn't cheat when checking whether a given keyword exists" do | |
@d.include?('fish').should be_false # if the method is empty, this test passes with nil returned | |
@d.add('fish') | |
@d.include?('fish').should be_true # confirms that it actually checks | |
@d.include?('bird').should be_false # confirms not always returning true after add | |
end | |
it "doesn't include a prefix that wasn't added as a word in and of itself" do | |
@d.add('fish') | |
@d.include?('fi').should be_false | |
end | |
it "doesn't find a word in empty dictionary" do | |
@d.find('fi').should be_empty # {} | |
end | |
it 'finds nothing if the prefix matches nothing' do | |
@d.add('fiend') | |
@d.add('great') | |
@d.find('nothing').should be_empty | |
end | |
it "finds an entry" do | |
@d.add('fish' => 'aquatic animal') | |
@d.find('fish').should == {'fish' => 'aquatic animal'} | |
end | |
it 'finds multiple matches from a prefix and returns the entire entry (keyword + definition)' do | |
@d.add('fish' => 'aquatic animal') | |
@d.add('fiend' => 'wicked person') | |
@d.add('great' => 'remarkable') | |
@d.find('fi').should == {'fish' => 'aquatic animal', 'fiend' => 'wicked person'} | |
end | |
it 'lists keywords alphabetically' do | |
@d.add('zebra' => 'African land animal with stripes') | |
@d.add('fish' => 'aquatic animal') | |
@d.add('apple' => 'fruit') | |
@d.keywords.should == %w(apple fish zebra) | |
end | |
it 'can produce printable output like so: [keyword] "definition"' do | |
@d.add('zebra' => 'African land animal with stripes') | |
@d.add('fish' => 'aquatic animal') | |
@d.add('apple' => 'fruit') | |
@d.printable.should == %Q{[apple] "fruit"\n[fish] "aquatic animal"\n[zebra] "African land animal with stripes"} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: dictionary</title> | |
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="../index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="../00_hello/index.html">00 Hello</a></li> | |
<li><a href="../01_temperature/index.html">01 Temperature</a></li> | |
<li><a href="../02_calculator/index.html">02 Calculator</a></li> | |
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li> | |
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li> | |
<li><a href="../09_timer/index.html">09 Timer</a></li> | |
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li>11 Dictionary</li> | |
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li> | |
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li><a href="../15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>dictionary</h1> | |
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Topics</h1> | |
<ul> | |
<li>Hash</li> | |
<li>Array</li> | |
<li>instance variables</li> | |
<li>regular expressions</li> | |
</ul> | |
</div> | |
<div class="tests"> | |
<h1>Tests</h1> | |
<a class="raw_file" href="dictionary_spec.rb">dictionary_spec.rb</a> | |
<pre> | |
require 'dictionary' | |
describe Dictionary do | |
before do | |
@d = Dictionary.new | |
end | |
it 'is empty when created' do | |
@d.entries.should == {} | |
end | |
it 'can add whole entries with keyword and definition' do | |
@d.add('fish' => 'aquatic animal') | |
@d.entries.should == {'fish' => 'aquatic animal'} | |
@d.keywords.should == ['fish'] | |
end | |
it 'add keywords (without definition)' do | |
@d.add('fish') | |
@d.entries.should == {'fish' => nil} | |
@d.keywords.should == ['fish'] | |
end | |
it 'can check whether a given keyword exists' do | |
@d.include?('fish').should be_false | |
end | |
it "doesn't cheat when checking whether a given keyword exists" do | |
@d.include?('fish').should be_false # if the method is empty, this test passes with nil returned | |
@d.add('fish') | |
@d.include?('fish').should be_true # confirms that it actually checks | |
@d.include?('bird').should be_false # confirms not always returning true after add | |
end | |
it "doesn't include a prefix that wasn't added as a word in and of itself" do | |
@d.add('fish') | |
@d.include?('fi').should be_false | |
end | |
it "doesn't find a word in empty dictionary" do | |
@d.find('fi').should be_empty # {} | |
end | |
it 'finds nothing if the prefix matches nothing' do | |
@d.add('fiend') | |
@d.add('great') | |
@d.find('nothing').should be_empty | |
end | |
it "finds an entry" do | |
@d.add('fish' => 'aquatic animal') | |
@d.find('fish').should == {'fish' => 'aquatic animal'} | |
end | |
it 'finds multiple matches from a prefix and returns the entire entry (keyword + definition)' do | |
@d.add('fish' => 'aquatic animal') | |
@d.add('fiend' => 'wicked person') | |
@d.add('great' => 'remarkable') | |
@d.find('fi').should == {'fish' => 'aquatic animal', 'fiend' => 'wicked person'} | |
end | |
it 'lists keywords alphabetically' do | |
@d.add('zebra' => 'African land animal with stripes') | |
@d.add('fish' => 'aquatic animal') | |
@d.add('apple' => 'fruit') | |
@d.keywords.should == %w(apple fish zebra) | |
end | |
it 'can produce printable output like so: [keyword] "definition"' do | |
@d.add('zebra' => 'African land animal with stripes') | |
@d.add('fish' => 'aquatic animal') | |
@d.add('apple' => 'fruit') | |
@d.printable.should == %Q{[apple] "fruit"\n[fish] "aquatic animal"\n[zebra] "African land animal with stripes"} | |
end | |
end</pre> | |
</div> | |
</div> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: rpn_calculator</title> | |
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="../index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="../00_hello/index.html">00 Hello</a></li> | |
<li><a href="../01_temperature/index.html">01 Temperature</a></li> | |
<li><a href="../02_calculator/index.html">02 Calculator</a></li> | |
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li> | |
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li> | |
<li><a href="../09_timer/index.html">09 Timer</a></li> | |
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li> | |
<li>12 Rpn Calculator</li> | |
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li> | |
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li><a href="../15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>rpn_calculator</h1> | |
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Topics</h1> | |
<ul> | |
<li>arrays</li> | |
<li>arithmetic</li> | |
<li>strings</li> | |
</ul> | |
<h1>RPN Calculator</h1> | |
<p>"RPN" stands for "Reverse Polish Notation". (See <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation">the wikipedia entry</a> for more information on this colorful term.) Briefly, in an RPN world, instead of using normal "infix" notation, e.g.</p> | |
<pre><code>2 + 2 | |
</code></pre> | |
<p>you use "postfix" notation, e.g.</p> | |
<pre><code>2 2 + | |
</code></pre> | |
<p>While this may seem bizarre, there are some advantages to doing things this way. For one, you never need to use parentheses, since there is never any ambiguity as to what order to perform operations in. The rule is, you always go from the back, or the left side.</p> | |
<pre><code>1 + 2 * 3 => | |
(1 + 2) * 3 or | |
1 + (2 * 3) | |
1 2 + 3 * => (1 + 2) * 3 | |
1 2 3 * + => 1 + (2 * 3) | |
</code></pre> | |
<p>Another advantage is that you can represent any mathematical formula using a simple and elegant data structure, called a <a href="http://en.wikipedia.org/wiki/Stack_(data_structure">stack</a>).</p> | |
<h1>Hints</h1> | |
<p>Ruby doesn't have a built-in stack, but the standard Array has all the methods you need to emulate one (namely, <code>push</code> and <code>pop</code>, and optionally <code>size</code>).</p> | |
</div> | |
<div class="tests"> | |
<h1>Tests</h1> | |
<a class="raw_file" href="rpn_calculator_spec.rb">rpn_calculator_spec.rb</a> | |
<pre> | |
# See | |
# * <http://en.wikipedia.org/wiki/Reverse_Polish_notation> | |
# * <http://www.calculator.org/rpn.aspx> | |
# | |
require "rpn_calculator" | |
describe RPNCalculator do | |
attr_accessor :calculator | |
before do | |
@calculator = RPNCalculator.new | |
end | |
it "adds two numbers" do | |
calculator.push(2) | |
calculator.push(3) | |
calculator.plus | |
calculator.value.should == 5 | |
end | |
it "adds three numbers" do | |
calculator.push(2) | |
calculator.push(3) | |
calculator.push(4) | |
calculator.plus | |
calculator.value.should == 7 | |
calculator.plus | |
calculator.value.should == 9 | |
end | |
it "subtracts the second number from the first number" do | |
calculator.push(2) | |
calculator.push(3) | |
calculator.minus | |
calculator.value.should == -1 | |
end | |
it "adds and subtracts" do | |
calculator.push(2) | |
calculator.push(3) | |
calculator.push(4) | |
calculator.minus | |
calculator.value.should == -1 | |
calculator.plus | |
calculator.value.should == 1 | |
end | |
it "multiplies and divides" do | |
calculator.push(2) | |
calculator.push(3) | |
calculator.push(4) | |
calculator.divide | |
calculator.value.should == (3.0 / 4.0) | |
calculator.times | |
calculator.value.should == 2.0 * (3.0 / 4.0) | |
end | |
it "resolves operator precedence unambiguously" do | |
# 1 2 + 3 * => (1 + 2) * 3 | |
calculator.push(1) | |
calculator.push(2) | |
calculator.plus | |
calculator.push(3) | |
calculator.times | |
calculator.value.should == (1+2)*3 | |
# 1 2 3 * + => 1 + (2 * 3) | |
calculator.push(1) | |
calculator.push(2) | |
calculator.push(3) | |
calculator.times | |
calculator.plus | |
calculator.value.should == 1+(2*3) | |
end | |
it "fails informatively when there's not enough values stacked away" do | |
expect { | |
calculator.plus | |
}.to raise_error("calculator is empty") | |
expect { | |
calculator.minus | |
}.to raise_error("calculator is empty") | |
expect { | |
calculator.times | |
}.to raise_error("calculator is empty") | |
expect { | |
calculator.divide | |
}.to raise_error("calculator is empty") | |
end | |
# extra credit | |
it "tokenizes a string" do | |
calculator.tokens("1 2 3 * + 4 5 - /").should == | |
[1, 2, 3, :*, :+, 4, 5, :-, :/] | |
end | |
# extra credit | |
it "evaluates a string" do | |
calculator.evaluate("1 2 3 * +").should == | |
((2 * 3) + 1) | |
calculator.evaluate("4 5 -").should == | |
(4 - 5) | |
calculator.evaluate("2 3 /").should == | |
(2.0 / 3.0) | |
calculator.evaluate("1 2 3 * + 4 5 - /").should == | |
(1.0 + (2 * 3)) / (4 - 5) | |
end | |
end</pre> | |
</div> | |
</div> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Topics | |
# * arrays | |
# * arithmetic | |
# * strings | |
# | |
# # RPN Calculator | |
# | |
# "RPN" stands for "Reverse Polish Notation". (See [the wikipedia entry](http://en.wikipedia.org/wiki/Reverse_Polish_notation) for more information on this colorful term.) Briefly, in an RPN world, instead of using normal "infix" notation, e.g. | |
# | |
# 2 + 2 | |
# | |
# you use "postfix" notation, e.g. | |
# | |
# 2 2 + | |
# | |
# While this may seem bizarre, there are some advantages to doing things this way. For one, you never need to use parentheses, since there is never any ambiguity as to what order to perform operations in. The rule is, you always go from the back, or the left side. | |
# | |
# 1 + 2 * 3 => | |
# (1 + 2) * 3 or | |
# 1 + (2 * 3) | |
# | |
# 1 2 + 3 * => (1 + 2) * 3 | |
# 1 2 3 * + => 1 + (2 * 3) | |
# | |
# Another advantage is that you can represent any mathematical formula using a simple and elegant data structure, called a [stack](http://en.wikipedia.org/wiki/Stack_(data_structure)). | |
# | |
# # Hints | |
# | |
# Ruby doesn't have a built-in stack, but the standard Array has all the methods you need to emulate one (namely, `push` and `pop`, and optionally `size`). | |
# | |
# See | |
# * <http://en.wikipedia.org/wiki/Reverse_Polish_notation> | |
# * <http://www.calculator.org/rpn.aspx> | |
# | |
require "rpn_calculator" | |
describe RPNCalculator do | |
attr_accessor :calculator | |
before do | |
@calculator = RPNCalculator.new | |
end | |
it "adds two numbers" do | |
calculator.push(2) | |
calculator.push(3) | |
calculator.plus | |
calculator.value.should == 5 | |
end | |
it "adds three numbers" do | |
calculator.push(2) | |
calculator.push(3) | |
calculator.push(4) | |
calculator.plus | |
calculator.value.should == 7 | |
calculator.plus | |
calculator.value.should == 9 | |
end | |
it "subtracts the second number from the first number" do | |
calculator.push(2) | |
calculator.push(3) | |
calculator.minus | |
calculator.value.should == -1 | |
end | |
it "adds and subtracts" do | |
calculator.push(2) | |
calculator.push(3) | |
calculator.push(4) | |
calculator.minus | |
calculator.value.should == -1 | |
calculator.plus | |
calculator.value.should == 1 | |
end | |
it "multiplies and divides" do | |
calculator.push(2) | |
calculator.push(3) | |
calculator.push(4) | |
calculator.divide | |
calculator.value.should == (3.0 / 4.0) | |
calculator.times | |
calculator.value.should == 2.0 * (3.0 / 4.0) | |
end | |
it "resolves operator precedence unambiguously" do | |
# 1 2 + 3 * => (1 + 2) * 3 | |
calculator.push(1) | |
calculator.push(2) | |
calculator.plus | |
calculator.push(3) | |
calculator.times | |
calculator.value.should == (1+2)*3 | |
# 1 2 3 * + => 1 + (2 * 3) | |
calculator.push(1) | |
calculator.push(2) | |
calculator.push(3) | |
calculator.times | |
calculator.plus | |
calculator.value.should == 1+(2*3) | |
end | |
it "fails informatively when there's not enough values stacked away" do | |
expect { | |
calculator.plus | |
}.to raise_error("calculator is empty") | |
expect { | |
calculator.minus | |
}.to raise_error("calculator is empty") | |
expect { | |
calculator.times | |
}.to raise_error("calculator is empty") | |
expect { | |
calculator.divide | |
}.to raise_error("calculator is empty") | |
end | |
# extra credit | |
it "tokenizes a string" do | |
calculator.tokens("1 2 3 * + 4 5 - /").should == | |
[1, 2, 3, :*, :+, 4, 5, :-, :/] | |
end | |
# extra credit | |
it "evaluates a string" do | |
calculator.evaluate("1 2 3 * +").should == | |
((2 * 3) + 1) | |
calculator.evaluate("4 5 -").should == | |
(4 - 5) | |
calculator.evaluate("2 3 /").should == | |
(2.0 / 3.0) | |
calculator.evaluate("1 2 3 * + 4 5 - /").should == | |
(1.0 + (2 * 3)) / (4 - 5) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: xml_document</title> | |
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="../index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="../00_hello/index.html">00 Hello</a></li> | |
<li><a href="../01_temperature/index.html">01 Temperature</a></li> | |
<li><a href="../02_calculator/index.html">02 Calculator</a></li> | |
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li> | |
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li> | |
<li><a href="../09_timer/index.html">09 Timer</a></li> | |
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li> | |
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li>13 Xml Document</li> | |
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li><a href="../15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>xml_document</h1> | |
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Topics</h1> | |
<ul> | |
<li>method_missing</li> | |
<li>blocks</li> | |
<li>strings</li> | |
<li>hashes</li> | |
</ul> | |
<h1>Builder</h1> | |
<p>Here we will implement the so-called Builder Pattern: we will make an object, XmlDocument, that <em>builds</em> an XML file, which can contain arbitrary tags.</p> | |
</div> | |
<div class="tests"> | |
<h1>Tests</h1> | |
<a class="raw_file" href="xml_document_spec.rb">xml_document_spec.rb</a> | |
<pre> | |
# Stuff you'll learn: | |
# method_missing | |
# nested closures | |
# "builder pattern" | |
require "xml_document" | |
describe XmlDocument do | |
before do | |
@xml = XmlDocument.new | |
end | |
it "renders an empty tag" do | |
@xml.hello.should == "<hello/>" | |
end | |
it "renders a tag with attributes" do | |
@xml.hello(:name => 'dolly').should == "<hello name='dolly'/>" | |
end | |
it "renders a randomly named tag" do | |
tag_name = (1..8).map{|i| ('a'..'z').to_a[rand(26)]}.join | |
@xml.send(tag_name).should == "<#{tag_name}/>" | |
end | |
it "renders block with text inside" do | |
@xml.hello do | |
"dolly" | |
end.should == "<hello>dolly</hello>" | |
end | |
it "nests one level" do | |
@xml.hello do | |
@xml.goodbye | |
end.should == "<hello><goodbye/></hello>" | |
end | |
it "nests several levels" do | |
xml = XmlDocument.new | |
xml.hello do | |
xml.goodbye do | |
xml.come_back do | |
xml.ok_fine(:be => "that_way") | |
end | |
end | |
end.should == "<hello><goodbye><come_back><ok_fine be='that_way'/></come_back></goodbye></hello>" | |
end | |
it "indents" do | |
@xml = XmlDocument.new(true) | |
@xml.hello do | |
@xml.goodbye do | |
@xml.come_back do | |
@xml.ok_fine(:be => "that_way") | |
end | |
end | |
end.should == | |
"<hello>\n" + | |
" <goodbye>\n" + | |
" <come_back>\n" + | |
" <ok_fine be='that_way'/>\n" + | |
" </come_back>\n" + | |
" </goodbye>\n" + | |
"</hello>\n" | |
end | |
end</pre> | |
</div> | |
</div> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Topics | |
# | |
# * method_missing | |
# * blocks | |
# * strings | |
# * hashes | |
# | |
# # Builder | |
# | |
# Here we will implement the so-called Builder Pattern: we will make an object, XmlDocument, that *builds* an XML file, which can contain arbitrary tags. | |
# Stuff you'll learn: | |
# method_missing | |
# nested closures | |
# "builder pattern" | |
require "xml_document" | |
describe XmlDocument do | |
before do | |
@xml = XmlDocument.new | |
end | |
it "renders an empty tag" do | |
@xml.hello.should == "<hello/>" | |
end | |
it "renders a tag with attributes" do | |
@xml.hello(:name => 'dolly').should == "<hello name='dolly'/>" | |
end | |
it "renders a randomly named tag" do | |
tag_name = (1..8).map{|i| ('a'..'z').to_a[rand(26)]}.join | |
@xml.send(tag_name).should == "<#{tag_name}/>" | |
end | |
it "renders block with text inside" do | |
@xml.hello do | |
"dolly" | |
end.should == "<hello>dolly</hello>" | |
end | |
it "nests one level" do | |
@xml.hello do | |
@xml.goodbye | |
end.should == "<hello><goodbye/></hello>" | |
end | |
it "nests several levels" do | |
xml = XmlDocument.new | |
xml.hello do | |
xml.goodbye do | |
xml.come_back do | |
xml.ok_fine(:be => "that_way") | |
end | |
end | |
end.should == "<hello><goodbye><come_back><ok_fine be='that_way'/></come_back></goodbye></hello>" | |
end | |
it "indents" do | |
@xml = XmlDocument.new(true) | |
@xml.hello do | |
@xml.goodbye do | |
@xml.come_back do | |
@xml.ok_fine(:be => "that_way") | |
end | |
end | |
end.should == | |
"<hello>\n" + | |
" <goodbye>\n" + | |
" <come_back>\n" + | |
" <ok_fine be='that_way'/>\n" + | |
" </come_back>\n" + | |
" </goodbye>\n" + | |
"</hello>\n" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Array Extension | |
# | |
# # Topics | |
# | |
# * objects, methods, classes | |
# * reopening classes | |
# | |
require "array_extensions" # we don't call it "array.rb" since that would be confusing | |
describe Array do | |
describe "#sum" do | |
it "has a #sum method" do | |
[].should respond_to(:sum) | |
end | |
it "should be 0 for an empty array" do | |
[].sum.should == 0 | |
end | |
it "should add all of the elements" do | |
[1,2,4].sum.should == 7 | |
end | |
end | |
describe '#square' do | |
it "does nothing to an empty array" do | |
[].square.should == [] | |
end | |
it "returns a new array containing the squares of each element" do | |
[1,2,3].square.should == [1,4,9] | |
end | |
end | |
describe '#square!' do | |
it "squares each element of the original array" do | |
array = [1,2,3] | |
array.square! | |
array.should == [1,4,9] | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: array_extensions</title> | |
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="../index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="../00_hello/index.html">00 Hello</a></li> | |
<li><a href="../01_temperature/index.html">01 Temperature</a></li> | |
<li><a href="../02_calculator/index.html">02 Calculator</a></li> | |
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li> | |
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li> | |
<li><a href="../09_timer/index.html">09 Timer</a></li> | |
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li> | |
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li> | |
<li>14 Array Extensions</li> | |
<li><a href="../15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>array_extensions</h1> | |
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Array Extension</h1> | |
<h1>Topics</h1> | |
<ul> | |
<li>objects, methods, classes</li> | |
<li>reopening classes</li> | |
</ul> | |
</div> | |
<div class="tests"> | |
<h1>Tests</h1> | |
<a class="raw_file" href="array_extensions_spec.rb">array_extensions_spec.rb</a> | |
<pre> | |
require "array_extensions" # we don't call it "array.rb" since that would be confusing | |
describe Array do | |
describe "#sum" do | |
it "has a #sum method" do | |
[].should respond_to(:sum) | |
end | |
it "should be 0 for an empty array" do | |
[].sum.should == 0 | |
end | |
it "should add all of the elements" do | |
[1,2,4].sum.should == 7 | |
end | |
end | |
describe '#square' do | |
it "does nothing to an empty array" do | |
[].square.should == [] | |
end | |
it "returns a new array containing the squares of each element" do | |
[1,2,3].square.should == [1,4,9] | |
end | |
end | |
describe '#square!' do | |
it "squares each element of the original array" do | |
array = [1,2,3] | |
array.square! | |
array.should == [1,4,9] | |
end | |
end | |
end</pre> | |
</div> | |
</div> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Topics | |
# | |
# * strings and numbers | |
# * modules | |
# * reopening classes | |
# | |
# # Extending a built-in class | |
# | |
# To make this test pass you'll need to extend a built-in class. You'll see that we're creating a new spec for 'Fixnum' -- this isn't a new class you'll be building, but instead it is a built-in class you will extend. | |
# | |
# Remember that in Ruby, everything is an object, even a number. Try this in irb: | |
# | |
# >> 4.class | |
# => Fixnum | |
# >> 4.methods | |
# \["inspect", "%", "<<", ... | |
# | |
# The number 4 is of class `FixNum` and it has methods on it. Your challenge is to add an `in_words` method to `FixNum`. | |
# | |
require "in_words" | |
describe Fixnum do | |
it "reads 0 to 9" do | |
0.in_words.should == 'zero' | |
1.in_words.should == 'one' | |
2.in_words.should == 'two' | |
3.in_words.should == 'three' | |
4.in_words.should == 'four' | |
5.in_words.should == 'five' | |
6.in_words.should == 'six' | |
7.in_words.should == 'seven' | |
8.in_words.should == 'eight' | |
9.in_words.should == 'nine' | |
end | |
it "reads 10 to 12" do | |
10.in_words.should == 'ten' | |
11.in_words.should == 'eleven' | |
12.in_words.should == 'twelve' | |
end | |
it "reads teens" do | |
13.in_words.should == 'thirteen' | |
14.in_words.should == 'fourteen' | |
15.in_words.should == 'fifteen' | |
16.in_words.should == 'sixteen' | |
17.in_words.should == 'seventeen' | |
18.in_words.should == 'eighteen' | |
19.in_words.should == 'nineteen' | |
end | |
it "reads tens" do | |
20.in_words.should == 'twenty' | |
30.in_words.should == 'thirty' | |
40.in_words.should == 'forty' | |
50.in_words.should == 'fifty' | |
60.in_words.should == 'sixty' | |
70.in_words.should == 'seventy' | |
80.in_words.should == 'eighty' | |
90.in_words.should == 'ninety' | |
end | |
it "reads various other numbers less than 100" do | |
20.in_words.should == 'twenty' | |
77.in_words.should == 'seventy seven' | |
99.in_words.should == 'ninety nine' | |
end | |
it "reads hundreds" do | |
100.in_words.should == 'one hundred' | |
200.in_words.should == 'two hundred' | |
300.in_words.should == 'three hundred' | |
123.in_words.should == 'one hundred twenty three' | |
777.in_words.should == 'seven hundred seventy seven' | |
818.in_words.should == 'eight hundred eighteen' | |
512.in_words.should == 'five hundred twelve' | |
999.in_words.should == 'nine hundred ninety nine' | |
end | |
it "reads thousands" do | |
1000.in_words.should == 'one thousand' | |
32767.in_words.should == 'thirty two thousand seven hundred sixty seven' | |
32768.in_words.should == 'thirty two thousand seven hundred sixty eight' | |
end | |
it "reads millions" do | |
10_000_001.in_words.should == 'ten million one' | |
end | |
it "reads billions" do | |
1_234_567_890.in_words.should == 'one billion two hundred thirty four million five hundred sixty seven thousand eight hundred ninety' | |
end | |
it "reads trillions" do | |
1_000_000_000_000.in_words.should == 'one trillion' | |
1_000_000_000_001.in_words.should == 'one trillion one' | |
1_888_259_040_036.in_words.should == 'one trillion eight hundred eighty eight billion two hundred fifty nine million forty thousand thirty six' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: in_words</title> | |
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="../index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="../00_hello/index.html">00 Hello</a></li> | |
<li><a href="../01_temperature/index.html">01 Temperature</a></li> | |
<li><a href="../02_calculator/index.html">02 Calculator</a></li> | |
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li> | |
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li> | |
<li><a href="../09_timer/index.html">09 Timer</a></li> | |
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li> | |
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li> | |
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li>15 In Words</li> | |
</ul> | |
</div> | |
<h1>in_words</h1> | |
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Topics</h1> | |
<ul> | |
<li>strings and numbers</li> | |
<li>modules</li> | |
<li>reopening classes</li> | |
</ul> | |
<h1>Extending a built-in class</h1> | |
<p>To make this test pass you'll need to extend a built-in class. You'll see that we're creating a new spec for 'Fixnum' -- this isn't a new class you'll be building, but instead it is a built-in class you will extend.</p> | |
<p>Remember that in Ruby, everything is an object, even a number. Try this in irb:</p> | |
<pre><code>>> 4.class | |
=> Fixnum | |
>> 4.methods | |
\["inspect", "%", "<<", ... | |
</code></pre> | |
<p>The number 4 is of class <code>FixNum</code> and it has methods on it. Your challenge is to add an <code>in_words</code> method to <code>FixNum</code>.</p> | |
</div> | |
<div class="tests"> | |
<h1>Tests</h1> | |
<a class="raw_file" href="in_words_spec.rb">in_words_spec.rb</a> | |
<pre> | |
require "in_words" | |
describe Fixnum do | |
it "reads 0 to 9" do | |
0.in_words.should == 'zero' | |
1.in_words.should == 'one' | |
2.in_words.should == 'two' | |
3.in_words.should == 'three' | |
4.in_words.should == 'four' | |
5.in_words.should == 'five' | |
6.in_words.should == 'six' | |
7.in_words.should == 'seven' | |
8.in_words.should == 'eight' | |
9.in_words.should == 'nine' | |
end | |
it "reads 10 to 12" do | |
10.in_words.should == 'ten' | |
11.in_words.should == 'eleven' | |
12.in_words.should == 'twelve' | |
end | |
it "reads teens" do | |
13.in_words.should == 'thirteen' | |
14.in_words.should == 'fourteen' | |
15.in_words.should == 'fifteen' | |
16.in_words.should == 'sixteen' | |
17.in_words.should == 'seventeen' | |
18.in_words.should == 'eighteen' | |
19.in_words.should == 'nineteen' | |
end | |
it "reads tens" do | |
20.in_words.should == 'twenty' | |
30.in_words.should == 'thirty' | |
40.in_words.should == 'forty' | |
50.in_words.should == 'fifty' | |
60.in_words.should == 'sixty' | |
70.in_words.should == 'seventy' | |
80.in_words.should == 'eighty' | |
90.in_words.should == 'ninety' | |
end | |
it "reads various other numbers less than 100" do | |
20.in_words.should == 'twenty' | |
77.in_words.should == 'seventy seven' | |
99.in_words.should == 'ninety nine' | |
end | |
it "reads hundreds" do | |
100.in_words.should == 'one hundred' | |
200.in_words.should == 'two hundred' | |
300.in_words.should == 'three hundred' | |
123.in_words.should == 'one hundred twenty three' | |
777.in_words.should == 'seven hundred seventy seven' | |
818.in_words.should == 'eight hundred eighteen' | |
512.in_words.should == 'five hundred twelve' | |
999.in_words.should == 'nine hundred ninety nine' | |
end | |
it "reads thousands" do | |
1000.in_words.should == 'one thousand' | |
32767.in_words.should == 'thirty two thousand seven hundred sixty seven' | |
32768.in_words.should == 'thirty two thousand seven hundred sixty eight' | |
end | |
it "reads millions" do | |
10_000_001.in_words.should == 'ten million one' | |
end | |
it "reads billions" do | |
1_234_567_890.in_words.should == 'one billion two hundred thirty four million five hundred sixty seven thousand eight hundred ninety' | |
end | |
it "reads trillions" do | |
1_000_000_000_000.in_words.should == 'one trillion' | |
1_000_000_000_001.in_words.should == 'one trillion one' | |
1_888_259_040_036.in_words.should == 'one trillion eight hundred eighty eight billion two hundred fifty nine million forty thousand thirty six' | |
end | |
end</pre> | |
</div> | |
</div> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: learn_ruby</title> | |
<link href="assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="00_hello/index.html">00 Hello</a></li> | |
<li><a href="01_temperature/index.html">01 Temperature</a></li> | |
<li><a href="02_calculator/index.html">02 Calculator</a></li> | |
<li><a href="03_simon_says/index.html">03 Simon Says</a></li> | |
<li><a href="04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li><a href="05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li><a href="06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li><a href="07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li><a href="08_book_titles/index.html">08 Book Titles</a></li> | |
<li><a href="09_timer/index.html">09 Timer</a></li> | |
<li><a href="10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li><a href="11_dictionary/index.html">11 Dictionary</a></li> | |
<li><a href="12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li><a href="13_xml_document/index.html">13 Xml Document</a></li> | |
<li><a href="14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li><a href="15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>learn_ruby</h1> | |
<div class="content"><h1>Advanced Setup</h1> | |
<h2>Pulling changes</h2> | |
<p>If you've been working for a while and then notice that the course repository has changed and you want the new stuff:</p> | |
<ul> | |
<li><p>View the "status" and make sure you have nothing modified</p> | |
<pre><code> git status | |
</code></pre></li> | |
<li><p>Pull the changes</p> | |
<pre><code> git pull origin master | |
</code></pre></li> | |
</ul> | |
<h2>Forking (not cloning)</h2> | |
<p>To save a copy of your own solutions in your own github repo, you'll have to "fork" the course on Github. This will give you a new git url of your very own, which you can then clone as above. For instance, if your github name is <code>ladyhaha</code>, your clone command is</p> | |
<pre><code> git clone git://github.com/ladyhaha/learn_ruby.git | |
</code></pre> | |
<p>To pull changes into this new repo is a little tricky and you should probably ask for help before doing it, but here's the instructions.</p> | |
<ul> | |
<li><p>Add a reference to the original remote repository</p> | |
<pre><code> git remote add ultrasaurus git://github.com/ultrasaurus/learn_ruby | |
</code></pre></li> | |
<li><p>Pull down the remote repository's master branch. This creates a local branch called <code>ultrasaurus/master</code></p> | |
<pre><code> git pull origin master | |
</code></pre></li> | |
<li><p>Now merge the <code>ultrasaurus/master</code> stuff into your <code>master</code> branch</p> | |
<pre><code> git merge ultrasaurus/master | |
</code></pre></li> | |
<li><p>Finally push your own <code>master</code> branch back to your <code>origin</code> remote github repository.</p> | |
<pre><code> git push origin master | |
</code></pre></li> | |
</ul> | |
<p>If you want to understand all these magical git incantations, watch this great screencast: <a href="http://blip.tv/file/4094854">http://blip.tv/file/4094854</a> (more at <a href="http://www.gitcasts.com">http://www.gitcasts.com</a>)</p> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Solarized Palette http://ethanschoonover.com/solarized */ | |
/* Font Stacks http://www.artsiteframework.com/guide/fontstacks.php */ | |
body { | |
background-color: white; | |
font-family: Optima, Candara, "Trebuchet MS", sans-serif; | |
margin: 0px; | |
font-size: 15px; | |
line-height: 19px; } | |
a, a:visited { | |
color: #268bd2; } | |
a:hover { | |
text-decoration: underline; } | |
a { | |
text-decoration: none; } | |
.content { | |
padding: 0 2em 0 18em; | |
min-height: 30em; | |
min-width: 20em; | |
max-width: 44em; | |
margin: 1em auto; } | |
.content h1, .content h2, .content h3 { | |
font-family: "Lucida Sans", "Lucida Grande", "Lucida Sans Unicode", Verdana, sans-serif; | |
margin-left: -1em; } | |
.content h1 { | |
text-shadow: #999 1px 1px 1px; | |
padding: .5em .25em; | |
margin-top: 1em; } | |
.content h2 { | |
margin-top: 1em; | |
border-bottom: #268bd2 1px dotted; } | |
.content pre { | |
overflow-x: auto; } | |
.header, .footer { | |
font-size: 80%; | |
padding: .25em; | |
background-color: #f2f2f2; } | |
.header { | |
border-bottom: 1px solid #002b36; | |
text-align: left; } | |
.header h1 { | |
color: #800000; | |
margin: 0 0 -8px 0; | |
padding: 0; | |
font: 30px/48px Optima, Candara, "Trebuchet MS", sans-serif; | |
letter-spacing: 0; } | |
.header h2 { | |
margin: 0 0 4px 13px; | |
padding: 0; | |
font: 10pt Optima, Candara, "Trebuchet MS", sans-serif; | |
color: #686868; | |
letter-spacing: 0; | |
font-variant: small-caps; } | |
.header a, .header a:visited { | |
color: #800000; | |
text-decoration: none; } | |
.header a:hover { | |
color: #37030B; | |
text-decoration: none; } | |
.footer { | |
border-top: 1px solid #002b36; | |
text-align: center; } | |
.nav { | |
float: left; | |
margin: 1em; | |
padding: 0 1em 1em; | |
width: 14em; | |
font-size: 75%; } | |
.nav { | |
background: -webkit-gradient(linear, left bottom, left top, color-stop(0.15, white), color-stop(0.85, #f2f2f2)); | |
background: -moz-linear-gradient(center bottom, white 15%, #f2f2f2 85%); | |
-moz-border-radius: 10px; | |
border-radius: 10px; | |
border: 1px solid black; } | |
.rspec_file > .tests { | |
position: relative; } | |
.rspec_file > .tests a.raw_file { | |
float: right; | |
position: absolute; | |
right: 0; | |
padding: 2px 4px; | |
margin: 3px; | |
border: 1px solid #666; | |
background: #ddd; } | |
pre { | |
font-family: "Lucida Sans Typewriter Regular", "lucida console", monaco, "andale mono", "bitstream vera sans mono", consolas, "DejaVu Sans Mono", Courier, "Courier New", monospace; | |
background-color: #e9e9ff; | |
padding: .5em 1em; | |
border: 1px solid #93a1a1; } | |
code { | |
font-family: "Lucida Sans Typewriter Regular", "lucida console", monaco, "andale mono", "bitstream vera sans mono", consolas, "DejaVu Sans Mono", Courier, "Courier New", monospace; | |
background-color: #efefff; } | |
pre > code { | |
background-color: #e9e9ff; } | |
li > p:nth-child(0) { | |
margin: 0; } | |
ul li ul li { | |
margin-top: .1em; | |
margin-bottom: 1em; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem "rake" | |
gem "rspec", ">=2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GEM | |
remote: https://rubygems.org/ | |
specs: | |
diff-lcs (1.2.5) | |
rake (10.3.2) | |
rspec (3.0.0) | |
rspec-core (~> 3.0.0) | |
rspec-expectations (~> 3.0.0) | |
rspec-mocks (~> 3.0.0) | |
rspec-core (3.0.3) | |
rspec-support (~> 3.0.0) | |
rspec-expectations (3.0.3) | |
diff-lcs (>= 1.2.0, < 2.0) | |
rspec-support (~> 3.0.0) | |
rspec-mocks (3.0.3) | |
rspec-support (~> 3.0.0) | |
rspec-support (3.0.3) | |
PLATFORMS | |
x86-mingw32 | |
DEPENDENCIES | |
rake | |
rspec (>= 2.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: learn_ruby</title> | |
<link href="assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="00_hello/index.html">00 Hello</a></li> | |
<li><a href="01_temperature/index.html">01 Temperature</a></li> | |
<li><a href="02_calculator/index.html">02 Calculator</a></li> | |
<li><a href="03_simon_says/index.html">03 Simon Says</a></li> | |
<li><a href="04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li><a href="05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li><a href="06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li><a href="07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li><a href="08_book_titles/index.html">08 Book Titles</a></li> | |
<li><a href="09_timer/index.html">09 Timer</a></li> | |
<li><a href="10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li><a href="11_dictionary/index.html">11 Dictionary</a></li> | |
<li><a href="12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li><a href="13_xml_document/index.html">13 Xml Document</a></li> | |
<li><a href="14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li><a href="15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>learn_ruby</h1> | |
<div class="content"><h1>Learn Ruby Test-First</h1> | |
<h2>Setup</h2> | |
<ul> | |
<li><p>Install Ruby</p> | |
<ul> | |
<li>You will need Ruby, RubyGems and RSpec to Learn Ruby.</li> | |
<li>We recommend using <a href="http://rvm.beginrescueend.com">rvm</a> but you can use any Ruby you want. We officially support Ruby 1.9 but probably work with 1.8.7 as well.</li> | |
<li>Here are some <a href="http://www.wiki.devchix.com/index.php?title=Workshop_Installation_Notes_Rails_3">good instructions</a> for installing the required software.</li> | |
<li>Here are some <a href="http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec:rubygems">other good instructions</a>, using rvm.</li> | |
</ul> | |
</li> | |
<li><p>Open a terminal window. (On Mac OS X you can use the <code>Terminal</code> app.)</p></li> | |
<li><p>Install RSpec</p> | |
<pre><code> gem install rspec | |
</code></pre></li> | |
<li><p>Enter the course directory. (That's the same directory that this <code>index.html</code> file is in.)</p> | |
<pre><code> cd learn_ruby | |
</code></pre></li> | |
<li><p>Enter the <code>00_hello</code> lab.</p> | |
<pre><code> cd 00_hello | |
</code></pre></li> | |
<li><p>Open the lab's <a href="./00_hello/index.html">index.html</a> file in a web browser and follow the instructions there.</p> | |
<pre><code> open index.html # this works on Mac OS X only! | |
</code></pre></li> | |
</ul> | |
<h2>Using These Exercises</h2> | |
<p>Your course directory has a list of lab directories. Each | |
directory has a spec file. You will write all the code to make all the specs | |
in it pass.</p> | |
<p>To get your feet wet in this process, go into the "hello" lab with <code>cd | |
00_hello</code> and read the detailed instructions in its <code>index.html</code> file.</p> | |
<p>If you got through "hello", then congratulations! Now it's time to go to the | |
next directory (whose name begins with <code>01_</code>) and start learning Ruby!</p> | |
<h2>Course Outline</h2> | |
<p>Each course is different, so check with your instructor for details on the | |
curriculum he or she has chosen. Here is a survey of a few of the labs:</p> | |
<ul> | |
<li><strong>hello</strong> | |
Gives you a feel for how to use these tests. | |
See <a href="00_hello/index.html">00_hello/index.html</a> for detailed instructions.</li> | |
<li><strong>temperature</strong> | |
Write and class and do some basic math.</li> | |
<li><strong>calculator</strong> introduces a little more math, and you'll need to iterate.</li> | |
<li><strong>pig_latin</strong> lets you manipulate strings.</li> | |
<li><strong>in_words</strong> asks a number to say itself in English. Extend a built-in class. By the end you'll use conditionals, arrays, iteration, and maybe even some recursion.</li> | |
<li><strong>blocks</strong> introduces block syntax, including <code>yield</code></li> | |
</ul> | |
<h1>Advanced Setup</h1> | |
<p>After you're in the swing of things, you can read about <a href="advanced_setup.html">advanced setup techniques</a> like pulling changes and forking. But don't worry about it at first.</p> | |
<h1>Problems? Questions?</h1> | |
<p>First, ask your neighbor. Then, ask your instructor.</p> | |
<p>Then ask Google (seriously!). If there's an error, try copying the error string and pasting it into a <a href="http://google.com">Google</a> search box. If that doesn't help, do a search on one of these sites:</p> | |
<ul> | |
<li><a href="http://stackoverflow.com/">http://stackoverflow.com/</a></li> | |
<li><a href="http://www.ruby-forum.com">http://www.ruby-forum.com</a></li> | |
</ul> | |
<p>You can also find help at the <a href="http://testfirst.org">TestFirst.org</a> site or the <a href="http://groups.google.com/group/test-first-teaching">Test-First Teaching mailing list</a>.</p> | |
<p>And many related lectures, notes and videos are at <a href="http://CodeLikeThis.com">http://CodeLikeThis.com</a>.</p> | |
<p>Remember, if you post a technical question online, you should</p> | |
<ol> | |
<li><p>Include version numbers:</p> | |
<pre><code> $ ruby -v | |
ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] | |
</code></pre></li> | |
<li><p>Note where you have already looked for an answer</p></li> | |
<li>If you can, include code snippets that reproduce the problem in isolation</li> | |
</ol> | |
<h1>Solutions and Submissions</h1> | |
<p>This Github repo (<code>learn_ruby</code>) is <em>generated</em> from a different Github repo, <a href="http://github.com/ultrasaurus/test-first-teaching">http://github.com/ultrasaurus/test-first-teaching</a>.</p> | |
<p>If you want to see how other students solved the problem, go to that repo and click around. (I'm not providing a direct link because I don't want it to be too easy to cheat!)</p> | |
<p>If you want to submit a patch or a solution, please fork the <a href="http://github.com/ultrasaurus/test-first-teaching">Test-First Teaching</a> repo and submit a Pull Request from there.</p> | |
<p>Also,</p> | |
<h1>Resources</h1> | |
<p>Here is a broad survey of many resources you may find useful. Don't try to read them all! Just browse around when you feel like learning more about Ruby.</p> | |
<h2>Learning Ruby via Tests (and/or Interactively)</h2> | |
<ul> | |
<li><a href="http://rubykoans.com">Ruby Koans</a> by Jim Weirich and Joe O'Brien (inspired by <a href="http://rubyquiz.com/quiz67.html">Metakoans</a> by ara.t.howard and <a href="http://clarkware.com/cgi/blosxom/2005/03/18">Ruby Learning Tests</a> by Mike Clark)</li> | |
<li><a href="http://testfirst.org">Test-First Teaching</a> by Sarah Allen and Alex Chaffee | |
<ul> | |
<li><a href="http://www.youtube.com/watch?v=KgfdlZuVz7I">Learning TDD Through Test First Teaching</a> talk by Sarah Allen at East Bay Ruby Meetup</li> | |
</ul> | |
</li> | |
<li><a href="http://www.exampler.com/blog/2009/12/17/growing-object-oriented-software-in-ruby/">Growing OO Software In Ruby</a> by Brian Marick - a Ruby version of <a href="http://www.growing-object-oriented-software.com/">Growing Object-Oriented Software Guided by Tests</a></li> | |
<li><a href="http://github.com/ryanb/ruby-warrior">ruby-warrior</a> by Ryan Bates - a game written in Ruby for learning Ruby</li> | |
<li><a href="https://github.com/JoshCheek/ruby-kickstart">Ruby Kickstart</a> by Josh Cheek - another set of test-driven exercises</li> | |
<li><a href="http://tryruby.org">Try Ruby</a> runs a Ruby interpreter in your browser, with hints and advice</li> | |
</ul> | |
<h2>Learning Ruby and Programming</h2> | |
<ul> | |
<li><a href="http://pine.fm/LearnToProgram/">Learn To Program</a> by <strong>Chris Pine</strong> - great Ruby tutorial, available online (1st ed.) or in a <a href="http://www.pragprog.com/titles/ltp2/learn-to-program-2nd-edition">PragProg book</a> (2nd ed.)</li> | |
<li><a href="http://rubylearning.com/satishtalim/tutorial.html">Ruby Learning</a> - Ruby tutorial</li> | |
<li><a href="http://railsforzombies.org">Rails for Zombies</a> - learn Ruby and Rails in your browser, no setup required</li> | |
<li><a href="http://ruby.learncodethehardway.org/">Learn Ruby The Hard Way</a> - a Ruby translation of Zed Shaw's "Learn Python The Hard Way"</li> | |
<li><a href="http://ruby.runpaint.org/">Read Ruby</a> a book about Ruby, quite technical but well written. Free online.</li> | |
<li><a href="http://github.com/alexch/mission">Ruby Mission</a></li> | |
<li><a href="http://groups.google.com/group/railsbridge">RailsBridge</a></li> | |
<li><a href="http://www.csunplugged.org/">CS Unplugged</a> - "CS Unplugged provides an extensive collection of free resources that teach principles of Computer Science such as binary numbers, algorithms and data compression through engaging games and puzzles that use cards, string, crayons and lots of running around."</li> | |
<li><a href="http://pragprog.com/titles/bmsft/everyday-scripting-with-ruby">Everyday Scripting with Ruby</a> by Brian Marick</li> | |
<li><a href="http://pragprog.com/titles/ruby/programming-ruby">Programming Ruby (the Pick Axe)</a> by Dave Thomas</li> | |
<li>Nice User's Guide: <a href="http://www.rubyist.net/~slagell/ruby/">http://www.rubyist.net/~slagell/ruby/</a></li> | |
<li>Michael Hartl's <a href="http://railstutorial.org">Rails Tutorial</a></li> | |
<li><a href="http://ruby4kids.com">http://ruby4kids.com</a></li> | |
<li><a href="http://jumpstartlab.com/resources/ruby-jumpstart/ruby/">Ruby in 100 Minutes</a> by <a href="http://jumpstartlab.com">Jeff Casimir</a></li> | |
<li><a href="http://university.rubymendicant.com">Ruby Mendicant University</a></li> | |
<li>Trainer on Rails <a href="http://www.public.traineronrails.com/courses/ruby/">"Ruby For Rails" tutorial</a></li> | |
<li><a href="http://yehudakatz.com/2009/08/24/my-10-favorite-things-about-the-ruby-language/">"My 10 Favorite Things About Ruby"</a> by Yehuda Katz</li> | |
<li><a href="http://stevenf.com/pages/book.html">"How To Count"</a> by Steven Frank, vol. 1 in "Programming for Mere Mortals", a series of books designed to introduce the concepts of programming from the ground up to a reader who has never written a line of code.</li> | |
</ul> | |
<h2>Test-Driven Development</h2> | |
<ul> | |
<li><a href="http://www.slideshare.net/alexchaffee/test-driven">Test-Driven</a> - presentation by Alex</li> | |
</ul> | |
<h2>Online Ruby References</h2> | |
<ul> | |
<li><a href="http://www.ruby-lang.org">http://www.ruby-lang.org</a></li> | |
<li><a href="http://www.ruby-doc.org/">http://www.ruby-doc.org/</a></li> | |
<li><a href="http://www.gotapi.com/rubyrails">http://www.gotapi.com/rubyrails</a></li> | |
<li><a href="http://apidock.com/">http://apidock.com/</a></li> | |
</ul> | |
<h2>Other good resources</h2> | |
<ul> | |
<li><code>irb</code> - when in doubt, try it out!</li> | |
<li><a href="http://rvm.beginrescueend.com/">Ruby Version Manager</a> (aka <code>rvm</code>) - cleanly manages multiple Ruby installations</li> | |
<li><a href="http://www.rubular.com/">http://www.rubular.com/</a> - an online Ruby regular expression calculator</li> | |
<li><a href="http://bit.ly/scott-chacon-git-101-tutorial">Git tutorial</a> by Scott Chacon</li> | |
</ul> | |
<h1>Credits</h1> | |
<ul> | |
<li>Concept by Alex Chaffee</li> | |
<li>Exercises by Alex Chaffee, Sarah Allen, Liah Hansen, Kai Middleton</li> | |
<li>Early quality assurance by Sumiki, Dimitri, Liah, Michael, and Brendan</li> | |
</ul> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This Rakefile has all the right settings to run the tests inside each lab | |
gem 'rspec', '~>2' | |
require 'rspec/core/rake_task' | |
task :default => :spec | |
desc "run tests for this lab" | |
RSpec::Core::RakeTask.new do |task| | |
lab = Rake.application.original_dir | |
task.pattern = "#{lab}/*_spec.rb" | |
task.rspec_opts = [ "-I#{lab}", "-I#{lab}/solution", '-f documentation', '-r ./rspec_config'] | |
task.verbose = false | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.configure do |c| | |
c.fail_fast = true | |
c.color = true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test-First Teaching: learn_ruby: learn_ruby</title> | |
<link href="assets/style.css" media="screen" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><a href="http://testfirst.org">TestFirst.org</a></h1> | |
<h2>the home of test-first teaching</h2> | |
</div> | |
<div class="nav"> | |
<h2><a href="index.html">learn_ruby</a></h2> | |
<b>Labs:</b> | |
<ul> | |
<li><a href="00_hello/index.html">00 Hello</a></li> | |
<li><a href="01_temperature/index.html">01 Temperature</a></li> | |
<li><a href="02_calculator/index.html">02 Calculator</a></li> | |
<li><a href="03_simon_says/index.html">03 Simon Says</a></li> | |
<li><a href="04_pig_latin/index.html">04 Pig Latin</a></li> | |
<li><a href="05_silly_blocks/index.html">05 Silly Blocks</a></li> | |
<li><a href="06_performance_monitor/index.html">06 Performance Monitor</a></li> | |
<li><a href="07_hello_friend/index.html">07 Hello Friend</a></li> | |
<li><a href="08_book_titles/index.html">08 Book Titles</a></li> | |
<li><a href="09_timer/index.html">09 Timer</a></li> | |
<li><a href="10_temperature_object/index.html">10 Temperature Object</a></li> | |
<li><a href="11_dictionary/index.html">11 Dictionary</a></li> | |
<li><a href="12_rpn_calculator/index.html">12 Rpn Calculator</a></li> | |
<li><a href="13_xml_document/index.html">13 Xml Document</a></li> | |
<li><a href="14_array_extensions/index.html">14 Array Extensions</a></li> | |
<li><a href="15_in_words/index.html">15 In Words</a></li> | |
</ul> | |
</div> | |
<h1>learn_ruby</h1> | |
<div class="content"><h1>Teacher Notes</h1> | |
<h2>Slides</h2> | |
<p>Some slides are in test-first-teaching/ruby_notes. They're in Markdown+Showoff format, which means they should be usable either as slides</p> | |
<pre><code>cd ruby_notes | |
showoff ruby_notes | |
</code></pre> | |
<p>or plain HTML</p> | |
<pre><code>cd ruby_notes | |
rdiscount *.md > index.html | |
</code></pre> | |
<h2>Rules (for students)</h2> | |
<ul> | |
<li>Always read the error!</li> | |
</ul> | |
<h2>Solutions</h2> | |
<p>The <code>solutions</code> branch is dead; long live the <code>solution</code> directory.</p> | |
<p>To add a solution, you must put your Ruby file(s) in a directory <strong>inside</strong> the lab directory with the name <code>solution</code>, e.g. <code>learn_ruby/hello/solution/hello.rb</code>.</p> | |
<p>Solutions only appear in the teacher repository (<code>test-first-teaching</code>) not the generated student repo (<code>learn_ruby</code>). When you run <code>rake</code> the tests will be run against the solutions, to assure that your code is correct.</p> | |
<p>Make sure not to check in any cruft in the lab directory, since that will be seen by (and surely befuddle) students.</p> | |
<p>Multiple solutions aren't supported yet.</p> | |
<h2>Notes and instructions</h2> | |
<p>Every lab has (or can have) a <code>index.md</code> file that the students can read. This is a good place for background, instructions and hints for solving the exercises.</p> | |
<p>Files ending with <code>.md</code> (Markdown) are converted to HTML and given a <code>.html</code> suffix, and files ending with <code>.scss</code> (Sass/SCSS) are converted to CSS and given a <code>.css</code> suffix. Any other files will be copied over to the student repo as is.</p> | |
<p>Lab directories become numbered; e.g. <code>hello</code> will become <code>00_hello</code>.</p> | |
<p>Each curriculum contains an <code>assets</code> directory, which is a good place to put shared files like <code>.js</code> and <code>.css</code> and images. You can refer to them using <code>..</code> in your markdown files, e.g.</p> | |
<pre><code>![logo](../assets/logo.gif) | |
</code></pre> | |
<p>This works in "preview mode" too, though it's a little weird, since <code>.scss</code> isn't converted into <code>.css</code> until the course is built using <code>rake build</code>.</p> | |
<p>There's also a <code>ubiquitous</code> directory, whose contents are copied into each and every generated lab directory.</p> | |
<h2>Tricks</h2> | |
<p>Here are some nice git config settings:</p> | |
<pre><code>git config --global alias.st status | |
git config --global alias.ci commit | |
git config --global alias.co checkout | |
git config --global alias.br branch | |
git config --global alias.unadd "reset HEAD" | |
git config --global alias.l "log --oneline --decorate --graph" | |
git config --global push.default matching | |
git config --global color.branch=auto | |
git config --global color.diff=auto | |
git config --global color.interactive=auto | |
git config --global color.status=auto | |
</code></pre> | |
<p>Or, you can edit <code>$HOME/.gitconfig</code> -- you should have sections like this:</p> | |
<pre><code>[color] | |
branch = auto | |
diff = auto | |
interactive = auto | |
status = auto | |
[alias] | |
st = status | |
ci = commit | |
co = checkout | |
br = branch | |
unadd = reset HEAD | |
l = log --oneline --decorate --graph | |
[push] | |
default = matching | |
</code></pre> | |
</div> | |
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment