From e15fe96dbbbc8ec91020df484c370e56d7647e52 Mon Sep 17 00:00:00 2001 From: Jonas Haskins Date: Tue, 15 Oct 2013 13:02:27 -0700 Subject: [PATCH 01/14] finished the homework! --- .rvmrc | 3 ++- week1/exercises/rspec_spec.rb | 30 ++++++++++++++++------ week1/homework/questions.txt | 32 ++++++++++++++++++++++++ week1/homework/strings_and_rspec_spec.rb | 29 ++++++++++++++++++--- 4 files changed, 81 insertions(+), 13 deletions(-) diff --git a/.rvmrc b/.rvmrc index 14c561b..e8cae02 100644 --- a/.rvmrc +++ b/.rvmrc @@ -6,7 +6,8 @@ # First we specify our desired [@], the @gemset name is optional, # Only full ruby name is supported here, for short names use: # echo "rvm use 2.0.0" > .rvmrc -environment_id="ruby-2.0.0-p247@RubyFall2013" +#environment_id="ruby-2.0.0-p247@RubyFall2013" +environment_id="ruby 1.9.3p392@RubyFall2013" # Uncomment the following lines if you want to verify rvm version per project # rvmrc_rvm_version="1.22.11 (stable)" # 1.10.1 seems like a safe start diff --git a/week1/exercises/rspec_spec.rb b/week1/exercises/rspec_spec.rb index 1e0a8ef..13103e1 100644 --- a/week1/exercises/rspec_spec.rb +++ b/week1/exercises/rspec_spec.rb @@ -43,11 +43,14 @@ # When this example fails, # it will show "expected" as 2, and "actual" as 1 - 1.should eq 2 + 1.should eq 1 end - - it "supports placeholder examples that lack code (like this one)" + + # jhjh + it "supports placeholder examples that lack code (like this one)" do + 1.should eq 1 + end it "requires that examples use expectations (like #should) to work properly" do @@ -71,21 +74,32 @@ end end + + ## JHJH added class tests + context "When Somethings Happens When I'm Logged In" do + it "should say Something" do + "Something".should eq "Something" + end + end + context "Examples for in-class test exploration" do it "should know order of operations" do # Fix the Failing Test # Order of Operations is Please Excuse My Dear Aunt Sally: # Parentheses, Exponents, Multiplication, Division, Addition, Subtraction - (1+2-5*6/2).should eq -13 + (1+2-5*6/2).should eq -12 end - it "should count the characters in your name" do - pending + + context "Count my name" do + it "should count the characters in your name" do + "Jonas".should have(5).characters + end end - it "should check basic math" + it "should check basic math" - it "should check basic spelling" + it "should check basic spelling" end diff --git a/week1/homework/questions.txt b/week1/homework/questions.txt index bd581a6..590ed60 100644 --- a/week1/homework/questions.txt +++ b/week1/homework/questions.txt @@ -1,15 +1,47 @@ Please read: Chapter 3 Classes, Objects, and Variables + p.86-90 Strings (Strings section in Chapter 6 Standard Types) 1. What is an object? +a instance of a class. 2. What is a variable? +a reference to a object 3. What is the difference between an object and a class? +a class is a combination of state and methods. an object is a instance of that class ( class instance ). + 4. What is a String? +A sequence of characters. 5. What are three messages that I can send to a string object? Hint: think methods +chomp, count, delete, empty? , length, upcase, downcase, split, squeeze! ... woah there are alot. + 6. What are two ways of defining a String literal? Bonus: What is the difference between the two? + +single or double quotation marks. + +single quotes 'foo', foo becomes the value. +For Double quotes, "foo\nbar" ruby looks for substitutions, interpolation "#{foo}" and escape sequences "Foo \nBar" + +also %q ( single quotes ), %Q ( double quotes ) + +%q/foo bar/ +%Q!oh no #{crap}! + +you can choose a delimiter. + +Finally here documents. + +string = << HERE + some kinda text + about something + i forgot what +HERE + + + +check them in and send a pull request !! diff --git a/week1/homework/strings_and_rspec_spec.rb b/week1/homework/strings_and_rspec_spec.rb index ea79e4c..ad7f623 100644 --- a/week1/homework/strings_and_rspec_spec.rb +++ b/week1/homework/strings_and_rspec_spec.rb @@ -12,14 +12,35 @@ before(:all) do @my_string = "Renée is a fun teacher. Ruby is a really cool programming language" end - it "should be able to count the charaters" + it "should be able to count the charaters" do + result = @my_string.count @my_string + result.should eq 66 + #puts "Count is #{result}" + + # These work to + # white space are characters to + # size = @my_string.size + # size.should eq 66 + # puts "Size is #{size}" + + # delete the white spaces ! + # @new_string = @my_string.delete(' ') + # size = @new_string.size + # size.should eq 55 + # puts "Size is #{size}" + + end + it "should be able to split on the . charater" do - pending - result = #do something with @my_string here + result = @my_string.split(".") result.should have(2).items end it "should be able to give the encoding of the string" do - pending 'helpful hint: should eq (Encoding.find("UTF-8"))' + #pending 'helpful hint: should eq (Encoding.find("UTF-8"))' + "#{@my_string.encoding}".should eq "UTF-8" + #puts "Encoding of #{@my_string.inspect} is #{@my_string.encoding}" + + end end end From 7e6e8bede98941dae2c896e650bd76db9d949a74 Mon Sep 17 00:00:00 2001 From: Jonas Haskins Date: Tue, 15 Oct 2013 18:06:12 -0700 Subject: [PATCH 02/14] my homework --- .DS_Store | Bin 0 -> 6148 bytes week1/.DS_Store | Bin 0 -> 6148 bytes week1/class_materials/name_printer_spec.rb | 8 ++++++ week1/homework/strings_and_rspec_spec_org.rb | 26 +++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 .DS_Store create mode 100644 week1/.DS_Store create mode 100644 week1/class_materials/name_printer_spec.rb create mode 100644 week1/homework/strings_and_rspec_spec_org.rb diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..77e2497419f05a3001b91c0dc34ad71e766ad1ba GIT binary patch literal 6148 zcmeHKOH0E*5Z>)W6I94W^tgB~(i9aB9zv<$QAnW&E1HmEgCQwRY7R9T|BeTLj=#s5 z-3_!fXAwIScE8zq?Bj#%gE7YYi@;{gVvHG35IHI}g63LRLkA;r*@x}t>CBH3zowhN zX~Ma;SU)R_Rg+hn#TTk6vjc4_mf2&q<8K#$=xuR_}=_p z>Y0}<(!MvBo?9=Qf=BAZB#A&D>*!G!WYY)hXt}h{FFK-Ibi~r`_0Brt(zc7jGz`=F zG!9QruWp9k^0jz-SM+hdhypskB@l&1M`NiFJRn@90;*K5pBP-F zgI(x2M`Ni_r86!^hJN(O)#HWB(ZMccIOC2&s)+$&V4Z=cYFc>yU&Aj``^aBUp%yVf z4E!?&cx&Je`miW{wr(sB&sqWH5ef>%m8gJ#zIF+K2JR!r(y9Ccb%=8`mI|>Kw99lr Ox(G-@s3Hb_fq@?^dPhhA literal 0 HcmV?d00001 diff --git a/week1/.DS_Store b/week1/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b5c60501588193cca54b84ef7e2e4602085f2c1d GIT binary patch literal 6148 zcmeHK%}T>S5T0$TCaBnp=yCB}q$w&MJcLleqtHSRR%&934a7#8)E;6rzK#bU$LDco zcdL{tf(MZ@6K223{Oq#dhTSXx2yYxZ09636Pzg&mHeU$ENf)GKJcL5^kwOn{!G{d` z3)$@Wj||Y-ZNW9fxN0drpX)b*2z@c6!6dy4;v~S#*WfOW(yU&86Qy!xWp&N6ZEK_3 ziH2b^@sjZ{OfOo4WYUVle&CNTm7V$7IQ9IIik$n|03*t7CrONU*JO91FdOu$J9+LL z9@S)hT9dicXdKk!vExjqwq@DX7i)WO|KzOg=MU4zCrzlpZ%@gl!5KWG@x$EiTccr| z3~w-V*2}D#kr`kHn1SVG!0dR|`tnYZXT}UL1HWW|_6Lbd=o&0Es;vVX`hBE$g^&bo zx=RpBgRa3sBSuh!E=AO(!dx+gE=RvKd9J}iqb>)bM#g^3$im!Egc=?FQl*1%HFC=g zFaz@pl=W+s&i~Wz@Bi~f{KgD0153q#s5Dzm52s|#)`iK@Su0VmP)R7S(D+e;hB}Hd fmyY6HR3+$_WFWc*3ytVO;U57-12@dTpEB?cR%1^9 literal 0 HcmV?d00001 diff --git a/week1/class_materials/name_printer_spec.rb b/week1/class_materials/name_printer_spec.rb new file mode 100644 index 0000000..4598c16 --- /dev/null +++ b/week1/class_materials/name_printer_spec.rb @@ -0,0 +1,8 @@ +describe "NamePrinter Application" do + + context "When Somethings Happens When I'm Logged In" do + it "should say Something" do + "Something".should eq "Something" + end + end +end diff --git a/week1/homework/strings_and_rspec_spec_org.rb b/week1/homework/strings_and_rspec_spec_org.rb new file mode 100644 index 0000000..ea79e4c --- /dev/null +++ b/week1/homework/strings_and_rspec_spec_org.rb @@ -0,0 +1,26 @@ +# encoding: utf-8 + +# Please make these examples all pass +# You will need to change the 3 pending tests +# You will need to write a passing test for the first example +# (Hint: If you need help refer to the in-class exercises) +# The two tests with the pending keyword, require some ruby code to be written +# (Hint: You should do the reading on Strings first) + +describe String do + context "When a string is defined" do + before(:all) do + @my_string = "Renée is a fun teacher. Ruby is a really cool programming language" + end + it "should be able to count the charaters" + it "should be able to split on the . charater" do + pending + result = #do something with @my_string here + result.should have(2).items + end + it "should be able to give the encoding of the string" do + pending 'helpful hint: should eq (Encoding.find("UTF-8"))' + end + end +end + From 1dfb52eb4b51ee9a08e686a043f4e6a540aa4c32 Mon Sep 17 00:00:00 2001 From: Jonas Haskins Date: Tue, 22 Oct 2013 16:10:43 -0700 Subject: [PATCH 03/14] Finished the homework questions, and the simon_says.rb module for homework --- .rvmrc | 49 ------------------------------------ week2/exercises/mad_libs.rb | 8 +++--- week2/homework/questions.txt | 27 +++++++++++++++++++- week2/homework/simon_says.rb | 38 ++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 54 deletions(-) delete mode 100644 .rvmrc create mode 100644 week2/homework/simon_says.rb diff --git a/.rvmrc b/.rvmrc deleted file mode 100644 index e8cae02..0000000 --- a/.rvmrc +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash - -# This is an RVM Project .rvmrc file, used to automatically load the ruby -# development environment upon cd'ing into the directory - -# First we specify our desired [@], the @gemset name is optional, -# Only full ruby name is supported here, for short names use: -# echo "rvm use 2.0.0" > .rvmrc -#environment_id="ruby-2.0.0-p247@RubyFall2013" -environment_id="ruby 1.9.3p392@RubyFall2013" - -# Uncomment the following lines if you want to verify rvm version per project -# rvmrc_rvm_version="1.22.11 (stable)" # 1.10.1 seems like a safe start -# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || { -# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading." -# return 1 -# } - -# First we attempt to load the desired environment directly from the environment -# file. This is very fast and efficient compared to running through the entire -# CLI and selector. If you want feedback on which environment was used then -# insert the word 'use' after --create as this triggers verbose mode. -if [[ -d "${rvm_path:-$HOME/.rvm}/environments" - && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] -then - \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id" - for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"* - do - if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]] - then \. "${__hook}" || true - fi - done - unset __hook - if (( ${rvm_use_flag:=1} >= 2 )) # display only when forced - then - if [[ $- == *i* ]] # check for interactive shells - then printf "%b" "Using: $(tput setaf 2 2>/dev/null)$GEM_HOME$(tput sgr0 2>/dev/null) -" # show the user the ruby and gemset they are using in green - else printf "%b" "Using: $GEM_HOME -" # don't use colors in non-interactive shells - fi - fi -else - # If the environment file has not yet been created, use the RVM CLI to select. - rvm --create "$environment_id" || { - echo "Failed to create RVM environment '${environment_id}'." - return 1 - } -fi diff --git a/week2/exercises/mad_libs.rb b/week2/exercises/mad_libs.rb index 3af5583..ac5d9b1 100644 --- a/week2/exercises/mad_libs.rb +++ b/week2/exercises/mad_libs.rb @@ -1,10 +1,10 @@ -puts "Please enter a noun" +print "Please enter a noun : " noun = gets.chomp -puts "Please enter an adjective" +print "Please enter an adjective : " adjective = gets.chomp -puts "Please enter a past tense action verb" +print "Please enter a past tense action verb : " verb_past_tense = gets.chomp -puts "What does the #{noun} say?" +print "What does the #{noun} say? : " says = gets.chomp story = "The #{adjective} #{noun} #{verb_past_tense} past the graveyard and says #{says}" puts story diff --git a/week2/homework/questions.txt b/week2/homework/questions.txt index 939e42d..f95391d 100644 --- a/week2/homework/questions.txt +++ b/week2/homework/questions.txt @@ -3,11 +3,36 @@ Containers, Blocks, and Iterators Sharing Functionality: Inheritance, Modules, and Mixins 1. What is the difference between a Hash and an Array? +An array is integer indexed collection of objects. + array_example[0] is the first object in the array. + +A hash is also a indexed collection of object references, except +in that it can be indexed with objects of any types : strings,symbols, ect.. integers also. +but arrays are just indexed by integers. + +my_hash = { 'black' => 'knight' } + +black (key) referes to knight ( value ) 2. When would you use an Array over a Hash and vice versa? -3. What is a module? Enumerable is a built in Ruby module, what is it? +I would use a hash for ordered items, and for efficent search/lookup +The key index will result in the value(s). Also to count frequencys. Using they +key and incrementing the value as the key was counted. + +An array would work great if I needed to store a collection of objects and the iterate +over it. If I needed a que or a stack i'd use a array. Or if i needed to split a string, +or read in variable input to a method. + +3. What is a module? +a way of grouping together methods, classes and constants. Modules define a namespace. + +Enumerable is a built in Ruby module, what is it? +Its a mixin. collection classes, traversal and searching methods and the ability to sort! 4. Can you inherit more than one thing in Ruby? How could you get around this problem? +No, Ruby is a single inheritance language. The child can only inherit from the parent. +You can get around the problem by using mixins, which provide a controlled multiple-inheritance like capability! 5. What is the difference between a Module and a Class? +a module can not be instantiated and a class can. diff --git a/week2/homework/simon_says.rb b/week2/homework/simon_says.rb new file mode 100644 index 0000000..93cb8b7 --- /dev/null +++ b/week2/homework/simon_says.rb @@ -0,0 +1,38 @@ +module SimonSays + def echo(says) + @says = says + end + + def shout(shouts) + @shouts = shouts + @shouts.upcase + end + + def repeat(word, *times) + @word = word + @times = times[0] + if @times == nil + @times = 2 + end + @word = "#{@word} " * @times + @word.rstrip + end + + def start_of_word(word, number) + a = word.split(//) + number = number - 1 + b = a[0..number] + b.join + end + + def first_word(word) + a = word.split(/ /) + a[0] + end + +end + +# Question .. is it correct to use instance variables here as in for +# echo/shout/repeat methods or better ( more ruby?? ) to use +# as in start_or_word and first_word ?? + From 433e2fe1e4e029bc1b1a14215a344c818bf1d15e Mon Sep 17 00:00:00 2001 From: Jonas Haskins Date: Thu, 24 Oct 2013 13:51:50 -0700 Subject: [PATCH 04/14] my book exe --- week2/exercises/book.rb | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/week2/exercises/book.rb b/week2/exercises/book.rb index 50bc054..9f52415 100644 --- a/week2/exercises/book.rb +++ b/week2/exercises/book.rb @@ -1,13 +1,28 @@ class Book + attr_accessor :title + attr_reader :page_count + #attr_reader :title #reader only ? + @@book_count = 0 + + #self. = class level + def self.book.count + ## @@ = class level varable + @@book_count + end - attr_accessor :title, :pages - - def initialize(title, pages) + def initalize title = "Not Set", page_count = 0 + @@book_count += 1 + @page_count = page_count @title = title - @pages = pages end - def page_count - "Page count is #{@pages}" + def test + @test = "Hellow!" end + + def out_put_test + puts @test + puts @@book_count + end + end From 3d0172c96078a4441362a4de57f9cde2928ba612 Mon Sep 17 00:00:00 2001 From: Jonas Haskins Date: Thu, 24 Oct 2013 13:52:13 -0700 Subject: [PATCH 05/14] spec file. --- week2/exercises/book_spec.rb | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/week2/exercises/book_spec.rb b/week2/exercises/book_spec.rb index bb22819..fa2aa9e 100644 --- a/week2/exercises/book_spec.rb +++ b/week2/exercises/book_spec.rb @@ -1,12 +1,26 @@ require './book.rb' describe Book do - before :each do - @book = Book.new("Harry Potter", 200) + + context "::book_count" do + + it "should count how many books have been created" do + Book.new + Book.new + Book.new + Book.book_count.should eq 3 end - it "should respond to title" do - @book.should respond_to "title" +end + + + + it "should should set some defaults" do + @book.new end + it "should allow me to set the title" do + @boot.title = "Harry Potter" + @book.title.should eq "Harry Potter" + it "should return the page count" do @book.page_count.should eq "Page count is 200" From 0fc7874de859c311437abc710971c1a8c3ae9aba Mon Sep 17 00:00:00 2001 From: Jonas Haskins Date: Thu, 24 Oct 2013 13:54:41 -0700 Subject: [PATCH 06/14] exercises and stuff ... --- week2/count_frequency.rb | 9 +++++++++ week2/exercises/spec.rb | 3 +++ week2/tester.rb | 20 ++++++++++++++++++++ week2/words_from_strings.rb | 5 +++++ week3/exercises/answers.jh | 27 +++++++++++++++++++++++++++ 5 files changed, 64 insertions(+) create mode 100644 week2/count_frequency.rb create mode 100644 week2/exercises/spec.rb create mode 100644 week2/tester.rb create mode 100644 week2/words_from_strings.rb create mode 100644 week3/exercises/answers.jh diff --git a/week2/count_frequency.rb b/week2/count_frequency.rb new file mode 100644 index 0000000..f28fb63 --- /dev/null +++ b/week2/count_frequency.rb @@ -0,0 +1,9 @@ +def count_frequency(word_list) + counts = Hash.new(0) + for word in word_list + counts[word] += 1 + end + counts +end + +p count_frequency(["sparky", "the", "cat", "sat", "on", "the", "mat"]) diff --git a/week2/exercises/spec.rb b/week2/exercises/spec.rb new file mode 100644 index 0000000..a90c483 --- /dev/null +++ b/week2/exercises/spec.rb @@ -0,0 +1,3 @@ +describe Book do + + context diff --git a/week2/tester.rb b/week2/tester.rb new file mode 100644 index 0000000..bb703aa --- /dev/null +++ b/week2/tester.rb @@ -0,0 +1,20 @@ +require_relative 'count_frequency' +require 'test/unit' + +class TestCountFrequency < Test::Unit::TestCase + def test_empty_list + assert_equal({}, count_frequency([])) + end + def test_single_word + assert_equal({"cat" => 1}, count_frequency(["cat"])) + end + def test_two_different_words + assert_equal({"cat" => 1, "sat" => 1}, count_frequency(["cat", "sat"])) + end + def test_two_words_with_adjacent_repeat + assert_equal({"cat" => 2, "sat" => 1}, count_frequency(["cat", "cat", "sat"])) + end + def test_two_words_with_non_adjacent_repeat + assert_equal({"cat" => 2, "sat" => 1}, count_frequency(["cat", "sat", "cat"])) + end +end diff --git a/week2/words_from_strings.rb b/week2/words_from_strings.rb new file mode 100644 index 0000000..e48cfcb --- /dev/null +++ b/week2/words_from_strings.rb @@ -0,0 +1,5 @@ +def words_from_string(string) + string.downcase.scan(/[\w']+/) +end + +p words_from_string("But I didn't inhale, he said (emphatically)") diff --git a/week3/exercises/answers.jh b/week3/exercises/answers.jh new file mode 100644 index 0000000..4425c1a --- /dev/null +++ b/week3/exercises/answers.jh @@ -0,0 +1,27 @@ +1.9.3-p392 :001 > load 'monsters.rb' + => true +1.9.3-p392 :002 > $monsters.count{|m| m[:nocturnal]} + => 2 +1.9.3-p392 :005 > $monsters.select{|m| m[:nocturnal]}.map{|m| m[:name]} + => ["Vampire", "Werewolf"] + +1.9.3-p392 :007 > $monsters.select{|m| m[:nocturnal]}.map{|m| m[:name]} + => ["Vampire", "Werewolf"] + +1.9.3-p392 :009 > legs = 0 + => 0 + +1.9.3-p392 :011 > $monsters.each{|m| legs += m[:legs]} + => [{:name=>"Zombie", :nocturnal=>false, :dangers=>["bites", "scratches"], :vulnerabilities=>["fire", "decapitation"], :legs=>2}, {:name=>"Mummy", :nocturnal=>false, :dangers=>["bites", "scratches", "curses"], :vulnerabilities=>["fire", "decapitation", "cats"], :legs=>2}, {:name=>"Vampire", :nocturnal=>true, :dangers=>["bites", "hypnosis"], :vulnerabilities=>["wood", "decapitation", "crosses", "holy_water", "garlic", "daylight"], :legs=>2}, {:name=>"Werewolf", :nocturnal=>true, :dangers=>["bites", "scratches"], :vulnerabilities=>["silver"], :legs=>4}, {:name=>"Blob", :nocturnal=>false, :dangers=>["suffocation"], :vulnerabilities=>["CO2", "ice", "cold"], :legs=>0}] +1.9.3-p392 :012 > legs + => 10 +1 + +counts the legs. shorthand. adds ( sum ) numbers in the array. +$monsters.map{|m| m[:legs]}.inject(:+) + + + +1.9.3-p392 :031 > dangers.inject(Hash.new(0)){|hist, danger| hist[danger]+=1 ;hist} + => {["bites", "scratches"]=>2, ["bites", "scratches", "curses"]=>1, ["bites", "hypnosis"]=>1, ["suffocation"]=>1} +1 From a2085b77fcccc55e105d155f5eb377ed7ecbbf9c Mon Sep 17 00:00:00 2001 From: Jonas Haskins Date: Tue, 29 Oct 2013 17:18:28 -0700 Subject: [PATCH 07/14] homework ! jonas haskins week 3 --- week3/homework/calculator.rb | 20 ++++++++++++++++++++ week3/homework/questions.txt | 9 +++++++++ 2 files changed, 29 insertions(+) create mode 100644 week3/homework/calculator.rb diff --git a/week3/homework/calculator.rb b/week3/homework/calculator.rb new file mode 100644 index 0000000..990f301 --- /dev/null +++ b/week3/homework/calculator.rb @@ -0,0 +1,20 @@ +# au jonas haskins +class Calculator + def sum(digits) + digits.inject 0, :+ + end + + def pow(v1, v2) + p = 1 + v2.times{ p *= v1 } + power = p + end + + def multiply(*nums) + nums.flatten.inject(:*) + end + + def fac(number) + (1..number).inject(:*) || 1 + end +end diff --git a/week3/homework/questions.txt b/week3/homework/questions.txt index dfb158d..e600832 100644 --- a/week3/homework/questions.txt +++ b/week3/homework/questions.txt @@ -5,11 +5,20 @@ Please Read: - Chapter 22 The Ruby Language: basic types (symbols), variables and constants 1. What is a symbol? +It is a object representing names and some strings inside the Ruby interpreter. +they are made by :some_name and :"string" literal syntax and by the to_sym 2. What is the difference between a symbol and a string? +a synbol is immutable. 3. What is a block and how do I call a block? +a block is code between two braces or between do - end +.. a way of grouping statements. +you call a block by calling yield or calling it as a Proc. 4. How do I pass a block to a method? What is the method signature? +a.method(&block) procs an ampersand 5. Where would you use regular expressions? +if you were matching any kind of string or pattern + From 24c4b92a53262fbc1e550de9e132e74a422a5364 Mon Sep 17 00:00:00 2001 From: sanojsniksah Date: Mon, 11 Nov 2013 11:12:48 -0800 Subject: [PATCH 08/14] Initial commit --- README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..61ad6c2 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +jonashaskins_midterm +==================== + +keeps my midter From a909850fc83ae544cc25011759e2c6217f254bb5 Mon Sep 17 00:00:00 2001 From: Jonas Haskins Date: Mon, 11 Nov 2013 11:14:06 -0800 Subject: [PATCH 09/14] Created the new depo and added the instructions to get started. --- instructions_and_questions.txt | 39 ++++++++++++++++++ mid_term_spec.rb | 74 ++++++++++++++++++++++++++++++++++ wish_list_spec.rb | 18 +++++++++ 3 files changed, 131 insertions(+) create mode 100644 instructions_and_questions.txt create mode 100644 mid_term_spec.rb create mode 100644 wish_list_spec.rb diff --git a/instructions_and_questions.txt b/instructions_and_questions.txt new file mode 100644 index 0000000..177358a --- /dev/null +++ b/instructions_and_questions.txt @@ -0,0 +1,39 @@ +Instructions for Mid-Term submission and Git Review (10pts): + - Create a git repository for your answers + - Add and Commit as you work through the questions and programming problems + - Your git log should reflect your work, don't just commit after you have finished working + - Use .gitignore to ignore any files that are not relevant to the midterm + - E-mail me your ssh public key + - I will email you back with your repository name + - Add a remote to your git repository: git@nird.us:RubyFall2013/YOURREPOSITORYNAME.git + - Push your changes to the remote + - After 6pm Tuesday November 19th you will not be able to push to your remote repository (or clone). + + Questions (20pts): + - What are the three uses of the curly brackets {} in Ruby? + - What is a regular expression and what is a common use for them? + - What is the difference between how a String, a symbol, a FixNum, and a Float are stored in Ruby? + - Are these two statements equivalent? Why or Why Not? + 1. x, y = "hello", "hello" + 2. x = y = "hello" +- What is the difference between a Range and an Array? +- Why would I use a Hash instead of an Array? +- What is your favorite thing about Ruby so far? +- What is your least favorite thing about Ruby so far? + + Programming Problems (10pts each): + - Write a passing rspec file called even_number_spec.rb that tests a class called EvenNumber. + - The EvenNumber class should: + - Only allow even numbers + - Get the next even number + - Compare even numbers + - Generate a range of even numbers +- Make the rspec tests in wish_list_spec.rb pass by writing a WishList class + - The WishList class should: + - Mixin Enumerable + - Define each so it returns wishes as strings with their index as part of the string + +Mid-Term Spec (50pts): +- Make the tests pass. + + diff --git a/mid_term_spec.rb b/mid_term_spec.rb new file mode 100644 index 0000000..0556a97 --- /dev/null +++ b/mid_term_spec.rb @@ -0,0 +1,74 @@ +require "#{File.dirname(__FILE__)}/turkey" + +describe Turkey do + + before do + @turkey = Turkey.new(10) + end + + it "should report the turkey weight" do + @turkey.weight.should equal 10 + end + + it "should be a kind of animal" do + @turkey.kind_of?(Animal).should be_true + end + + it "should gobble speak" do + @turkey.gobble_speak("Hello I Am a Turkey. Please Don't Eat Me.").should eq "Gobble Gobble Gobble gobble Gobble. Gobble Gobb'le Gobble Gobble." + end + +end + +require "#{File.dirname(__FILE__)}/thanksgiving_dinner" + +describe ThanksgivingDinner do + + before do + @t_dinner = ThanksgivingDinner.new(:vegan) + @t_dinner.guests = ["Aunt Petunia", "Uncle Vernon", "Aunt Marge", "Dudley", "Harry"] # I know I just made a British family celebrate Thanksgiving, but it could be worse: It could have been the 4th of July! :) + end + + it "should be a kind of dinner" do + @t_dinner.kind_of?(Dinner).should be_true + end + + # Use inject here + it "should sum the letters in each guest name for the seating chart size" do + @t_dinner.seating_chart_size.should eq 45 + end + + it "should provide a menu" do + @t_dinner.respond_to?(:menu).should be_true + end + + context "#menu" do + + it "should have a diet specified" do + @t_dinner.menu[:diet].should eq :vegan + end + + it "should have proteins" do + @t_dinner.menu[:proteins].should eq ["Tofurkey", "Hummus"] + end + + it "should have vegetables" do + @t_dinner.menu[:veggies].should eq [:ginger_carrots , :potatoes, :yams] + end + + # Dinners don't always have dessert, but ThanksgivingDinners always do! + it "should have desserts" do + @t_dinner.menu[:desserts].should eq({:pies => [:pumkin_pie], :other => ["Chocolate Moose"], :molds => [:cranberry, :mango, :cherry]}) + end + + end + + # Use String interpolation, collection methods, and string methods for these two examples + it "should return what is on the dinner menu" do + @t_dinner.whats_for_dinner.should eq "Tonight we have proteins Tofurkey and Hummus, and veggies Ginger Carrots, Potatoes, and Yams." + end + + it "should return what is on the dessert menu" do + @t_dinner.whats_for_dessert.should eq "Tonight we have 5 delicious desserts: Pumkin Pie, Chocolate Moose, and 3 molds: Cranberry and Mango and Cherry." + end +end diff --git a/wish_list_spec.rb b/wish_list_spec.rb new file mode 100644 index 0000000..1ae634a --- /dev/null +++ b/wish_list_spec.rb @@ -0,0 +1,18 @@ +require "#{File.dirname(__FILE__)}/wish_list" + +describe WishList do + before :each do + @wish_list = WishList.new + @wish_list.wishes = ["Lamborghini", "Corn Starch and Water Moat", "Vegan Bacon Ice Cream", "Rubber Chicken", "Free Tickets to Ender's Game"] + end + + it "should mixin Enumerable" do + @wish_list.is_a?(Enumerable).should be_true + end + + context "#each" do + it "should give me a numberd list" do + @wish_list.map{|w| w}.should eq ["1. Lamborghini", "2. Corn Starch and Water Moat", "3. Vegan Bacon Ice Cream", "4. Rubber Chicken", "5. Free Tickets to Ender's Game"] + end + end +end \ No newline at end of file From 24496d5b1c6f5c7077469234a0008ddd467b3acd Mon Sep 17 00:00:00 2001 From: Jonas Haskins Date: Tue, 12 Nov 2013 13:48:55 -0800 Subject: [PATCH 10/14] first draft of working even numbers and even numberes spec. --- midterm/even_number.rb | 19 +++++++++++++++++++ midterm/even_number_spec.rb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 midterm/even_number.rb create mode 100644 midterm/even_number_spec.rb diff --git a/midterm/even_number.rb b/midterm/even_number.rb new file mode 100644 index 0000000..69deda8 --- /dev/null +++ b/midterm/even_number.rb @@ -0,0 +1,19 @@ +class EvenNumber + + def even(number) + number.even? + end + + def next_even(nextnumber) + nexteven = nextnumber + 2 + end + + def compair(num1, num2) + num1 <=> num2 + end + + def makerange(range) + a = range + b = a.select {|x| x.even? } + end +end diff --git a/midterm/even_number_spec.rb b/midterm/even_number_spec.rb new file mode 100644 index 0000000..8bce78f --- /dev/null +++ b/midterm/even_number_spec.rb @@ -0,0 +1,32 @@ +require "#{File.dirname(__FILE__)}/even_number" + +describe EvenNumber do + + before do + @number = EvenNumber.new + end + + it "Should only allow even numbers" do + @number.even(6).should eq true + @number.even(7).should eq false + end + + it "Should get the next even number" do + a = 10 + b = a + 2 + @number.next_even(a).should == b + end + + it "Should compair two even numbers" do + @number.compair(8, 8).should == 0 + @number.compair(8, 6).should == 1 + @number.compair(6, 8).should == -1 + end + + it "Should generate a range of even numbers" do + a = 2..20 + b = a.select {|x| x.even? } + @number.makerange(2..20).should eq b + end + +end From 978f2c25b5c847d329ea52d3882640aae707e074 Mon Sep 17 00:00:00 2001 From: Jonas Haskins Date: Tue, 26 Nov 2013 17:22:04 -0800 Subject: [PATCH 11/14] homework for week 7 --- .../features/step_definitions/converter.rb | 26 ++++++++++++++++++ .../step_definitions/.pirate_steps.rb.swp | Bin 0 -> 12288 bytes .../features/step_definitions/pirate.rb | 23 ++++++++++++++++ .../features/step_definitions/pirate_steps.rb | 1 + .../step_definitions/rspec/expectations.rb | 1 + .../rspec/mocks/standalone.rb | 1 + week7/homework/questions.txt | 23 ++++++++++++++++ 7 files changed, 75 insertions(+) create mode 100644 week7/exercises/features/step_definitions/converter.rb create mode 100644 week7/homework/features/step_definitions/.pirate_steps.rb.swp create mode 100644 week7/homework/features/step_definitions/pirate.rb create mode 100644 week7/homework/features/step_definitions/rspec/expectations.rb create mode 100644 week7/homework/features/step_definitions/rspec/mocks/standalone.rb diff --git a/week7/exercises/features/step_definitions/converter.rb b/week7/exercises/features/step_definitions/converter.rb new file mode 100644 index 0000000..0df5bfb --- /dev/null +++ b/week7/exercises/features/step_definitions/converter.rb @@ -0,0 +1,26 @@ +Given(/^I have entered (\d+) into the converter$/) do |arg1| + # pending # express the regexp above with the code you wish you had + @temp +end + +Given(/^I set the type to Fahrenheit$/) do + # pending # express the regexp above with the code you wish you had + @type = 'Fahrenheit' +end + +When(/^I press convert$/) do + +end + +Then(/^the result returned should be (\d+)\.(\d+)$/) do |arg1, arg2| + #pending # express the regexp above with the code you wish you had + class Convert + def self + n = (@temp - 32) * 5 / 9 + n.round(1) + end + end + + +end + diff --git a/week7/homework/features/step_definitions/.pirate_steps.rb.swp b/week7/homework/features/step_definitions/.pirate_steps.rb.swp new file mode 100644 index 0000000000000000000000000000000000000000..ad1f8ee1af025d0937a9be42d4a701e261236358 GIT binary patch literal 12288 zcmeI&&uSAv90%};HxE^@J$MnuRA@rYZkim5hd_;>1{;x-3PLrVWGC4*lbK~^wxL?> z!DsLl^dRWLn{OiM%?I!i{H0AHX$W|=d%g$8^0* zlPj)F`rNsG@`w%s5P$##AOHafKmY;|fB*y_0D=EdKtzoFT4Jnmg^H*D|IdE^|GdiB zH_BJa7s`7|MA@gbDR(J1C@Yj@%5Pf#o${ITiSm(hKxtCOdq1L}K>z{}fB*y_009U< z00Izzzy%PHI%1c%=tJ#H`M{+r@rC@J=J{fvgrkwzWGdpd8W*