Two Plus Two Publishing LLC Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > >

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old 03-13-2012, 06:26 PM   #26
clowntable
Carpal \'Tunnel
 
clowntable's Avatar
 
Join Date: Jun 2006
Location: 39, 46, 56, 59, 191
Posts: 45,289
Re: Coursera SaaS class (Ruby+Rails) discussion

hw1_2

rps.feature:
Code:
Feature: Play RPS

I want to be able to play RPS against one opponent because it's fun.

Scenario Outline: Two player RPS
  Given "<player_one>" threw "<throw_one>"
  When "<player_two>" throws "<throw_two>"
  Then the oputput should be "<output>"
  
Examples:
  |player_one|throw_one|player_two|throw_two|output|
  |Armando|P|Dave|S|Dave,S|
  |Dave|S|Armando|P|Dave,S|
  |Armando|R|Dave|R|Armando,R|
  |Armando|r|Dave|p|Dave,p|
rps_steps.rb:
Code:
require_relative 'hw1_2.rb'

Given /^"([^"]*)" threw "([^"]*)"$/ do |player_one, throw_one|
  @player_one = [player_one, throw_one]
end

When /^"([^"]*)" throws "([^"]*)"$/ do |player_two, throw_two|
  @player_two = [player_two, throw_two]
end

Then /^the oputput should be "([^"]*)"$/ do |winner|
  game = [@player_one, @player_two]
  expected_output = winner.split(',')
  raise "Wrong Output" unless expected_output == rps_game_winner(game)
end
rps_tournament.feature:
Code:
Feature: Play an RPS torunament

I want to be able to play an entire RPS tournament because it's more fun than a single gamefun.

Scenario: RPS tournament [ ["Armando", "P"], ["Kris", "S"] ]
  Given A tournament that looks like [ ["Armando", "P"], ["Kris", "S"] ]
  When The tournament engine is run
  Then the tournament oputput should be ["Kris", "S"]
  
Scenario: RPS tournament [ [ [ "Allen", "P" ], [ "Dave", "S" ] ],[ [ "Richard", "R" ] , [ "Armando", "P" ] ]]
  Given A tournament that looks like [ [ [ "Allen", "P" ], [ "Dave", "S" ] ],[ [ "Richard", "R" ] , [ "Armando", "P" ] ]]
  When The tournament engine is run
  Then the tournament oputput should be ["Dave", "S"]
  
Scenario: RPS tournament [ [ [ "Allen", "p" ], [ "Dave", "P" ] ],[ [ "Richard", "R" ] , [ "Armando", "P" ] ]]
  Given A tournament that looks like [ [ [ "Allen", "p" ], [ "Dave", "P" ] ],[ [ "Richard", "R" ] , [ "Armando", "P" ] ]]
  When The tournament engine is run
  Then the tournament oputput should be ["Allen", "p"]
  
Scenario: RPS tournament [[ [ [ "Allen", "P" ], [ "Dave", "S" ] ],[ [ "Richard", "R" ] , [ "Armando", "P" ] ]], [ [ [ "Omer", "P" ], [ "David", "S" ] ],[ [ "Max", "R" ] , [ "Jonathan", "P" ] ]], ]
  Given A tournament that looks like [[ [ [ "Allen", "P" ], [ "Dave", "S" ] ],[ [ "Richard", "R" ] , [ "Armando", "P" ] ]], [ [ [ "Omer", "P" ], [ "David", "S" ] ],[ [ "Max", "R" ] , [ "Jonathan", "P" ] ]], ]
  When The tournament engine is run
  Then the tournament oputput should be ["Dave", "S"]
rps_tournament_steps.rb:
Code:
require_relative 'hw1_2.rb'

# Some examples of tournaments
tournament_one = [ ["Armando", "P"], ["Dave", "S"] ]
tournament_two = [ 
  [ [ "Allen", "P" ], [ "Dave", "S" ] ],
  [ [ "Richard", "R" ] , [ "Armando", "P" ] ]
]
tournament_three = [
  [ 
     [ [ "Allen", "P" ], [ "Dave", "S" ] ],
     [ [ "Richard", "R" ] , [ "Armando", "P" ] ]
  ], 
  [ 
     [ [ "Omer", "P" ], [ "David", "S" ] ],
     [ [ "Max", "R" ] , [ "Jonathan", "P" ] ]
  ], 
]

Given /^A tournament that looks like (.*)$/ do |tournament|
  @tournament = tournament
end

When /^The tournament engine is run$/ do
  tournament = eval(@tournament)
  @output = rps_tournament_winner(tournament).to_s
end

Then /^the tournament oputput should be (.*)$/ do |expected_output|
  raise "Wrong Output" unless expected_output == @output
end
hw1_2.rb:
Spoiler:
clowntable is offline   Reply With Quote
Old 03-13-2012, 06:29 PM   #27
clowntable
Carpal \'Tunnel
 
clowntable's Avatar
 
Join Date: Jun 2006
Location: 39, 46, 56, 59, 191
Posts: 45,289
Re: Coursera SaaS class (Ruby+Rails) discussion

hw1_3

anagram_spec.rb:
Code:
require_relative '../hw1_3_new.rb'

sample_list = ['cars', 'for', 'potatoes', 'racs', 'four','scar', 'creams',
'scream']

describe "anagram?" do
  it "should return true for equal words" do
    anagram?('house','house').should be_true
  end
  it "should return true for equal words with different capitalization" do
    anagram?('hoUsE','house').should be_true
  end
  it "should return false for different words that aren't anagrams'" do
    anagram?('house','wall').should be_false
  end
  it "should return true for anagrams" do
    anagram?('cars','rcas').should be_true
  end
end

describe "combine anagrams" do
  it "should return a list" do
    combine_anagrams(['cars']).class.should be Array 
  end
  it "should return the same list case sensitive if the count is one" do
    combine_anagrams(['cars']).should == [['cars']]
    combine_anagrams(['Cars']).should == [['Cars']]
  end
  it "should work for simple examples" do
    combine_anagrams(['ab','aa','ba']).sort.should == [['aa'],['ab','ba']].sort
    combine_anagrams(['ab','aa','cc','ba',]).sort.should == [['aa'],['ab','ba'],['cc']].sort
    combine_anagrams(['ab','aa','ba','cc']).sort.should == [['aa'],['ab','ba'],['cc']].sort
  end
  it "should handle a simple case of some repeated single-character inputs" do
    combine_anagrams(['a','a','b','c','d','b']).sort.should == [['a', 'a'], ['b', 'b'], ['c'], ['d']]
  end
  
  it "should work for the testcase ['cars', 'for', 'potatoes', 'racs', 'four','scar', 'creams',
'scream']" do
    combine_anagrams(['cars', 'for', 'potatoes', 'racs', 'four','scar', 'creams',
'scream']).sort.should == [["cars", "racs", "scar"], ["four"], ["for"],
["potatoes"], ["creams", "scream"]].sort
  end
end
hw1_3_new.rb
Spoiler:
clowntable is offline   Reply With Quote
Old 03-13-2012, 06:31 PM   #28
clowntable
Carpal \'Tunnel
 
clowntable's Avatar
 
Join Date: Jun 2006
Location: 39, 46, 56, 59, 191
Posts: 45,289
Re: Coursera SaaS class (Ruby+Rails) discussion

1_4 is trivial so I'll skip it...1_5:
hw1_5_spec.rb:
Code:
require_relative '../hw1_5.rb'

describe Foo do
  before(:each) do
    @foo = Foo.new
  end
  it "should exist" do
    foo_new = Foo.new
  end
  it "should have a getter for bar" do
    @foo.methods.should include(:bar)
  end
  it "should have getter for bar_history" do
    @foo.methods.should include(:bar_history)
  end
  it "should have a setter for bar" do
    @foo.bar = 3
    @foo.bar.should == 3
  end
  it "should have an empty history at first" do
    @foo.bar_history.should == nil
  end
  it "should remember history" do
    @foo.bar = 3
    @foo.bar = :wowzo
    @foo.bar = 'boo!'
    @foo.bar_history.should == [nil, 3, :wowzo, 'boo!']
  end
  it "should maintain instance variables seperately for each object instance" do
    foo = Foo.new
    foo.bar = 1
    foo.bar = 2
    foo = Foo.new
    foo.bar = 4
    foo.bar_history.should == [nil, 4]
  end
  it "should work for class Baz with methodname lolcat" do
    baz = Baz.new
    baz.lolcat = 'can i'
    baz.lolcat = 'haz'
    baz.lolcat = 'cheesburger?'
    baz.lolcat_history.should == [nil, 'can i', 'haz', 'cheesburger?']
  end
end
hw1_5.rb
Spoiler:
clowntable is offline   Reply With Quote
Old 03-14-2012, 08:45 PM   #29
skier_5
Pooh-Bah
 
skier_5's Avatar
 
Join Date: Jan 2006
Location: London
Posts: 5,433
Re: Coursera SaaS class (Ruby+Rails) discussion

My solutions:

1) Almost the same as clowntable's, except I specified a default value of 0 for the hash, which allowed me to omit the conditional inside the loop.

2)
Spoiler:


3) I had some trouble finding the string sorting method..
Spoiler:


5) Same as clowntable's
skier_5 is offline   Reply With Quote
Old 03-15-2012, 01:49 AM   #30
clowntable
Carpal \'Tunnel
 
clowntable's Avatar
 
Join Date: Jun 2006
Location: 39, 46, 56, 59, 191
Posts: 45,289
Re: Coursera SaaS class (Ruby+Rails) discussion

To get good allignment and avoid smilies etc:
put [ code ] [ /code ] around your code in posts (without the spaces in the tags)
clowntable is offline   Reply With Quote
Old 03-15-2012, 04:10 PM   #31
candybar
old hand
 
Join Date: Aug 2011
Posts: 1,357
Re: Coursera SaaS class (Ruby+Rails) discussion

HW1 Prob3 can be done slightly simpler relying on more built-in functionality:

Code:
def combine_anagrams(words)
  result_hash = Hash.new { |hash, key| hash[key] = [] }
  words.each do |word|
    hashkey = word.downcase.split(//).sort.join
    result_hash[hashkey] = result_hash[hashkey].push(word)
  end
  result_hash.values
end
candybar is offline   Reply With Quote
Old 03-19-2012, 02:16 AM   #32
candybar
old hand
 
Join Date: Aug 2011
Posts: 1,357
Re: Coursera SaaS class (Ruby+Rails) discussion

Cucumber was kind of fun to learn and somewhat cute but is this really useful? Why use a language whose best feature is resemblance to English to write tests, if you have to use regex to extend/parse the language anyhow?
candybar is offline   Reply With Quote
Old 03-19-2012, 11:30 AM   #33
clowntable
Carpal \'Tunnel
 
clowntable's Avatar
 
Join Date: Jun 2006
Location: 39, 46, 56, 59, 191
Posts: 45,289
Re: Coursera SaaS class (Ruby+Rails) discussion

The entire reason is to tap into more domain expert knowledge/work with customers (imo). If you just work on your own projects I'm pretty sure you could simply stick to rspec.

But if you think about a typical project, Cucumber starts to make way more sense. Just imagine sitting at a table with a customer and collectiong feature, feature, feature, feature then scenarios for the features, then estimate work/feature. You can collect this stuff in Cucumber already and have a decent outline of what you need to do with acceptance criteria etc.
All the customer is ever going to see is the feature files

It probably also helps to clear up stuff etc (and you have some sort of minimalistic documentation of what the system is supposed to do, there's some neat output to pdf and whatnot stuff)
clowntable is offline   Reply With Quote
Old 03-20-2012, 02:23 AM   #34
gaming_mouse
Carpal \'Tunnel
 
gaming_mouse's Avatar
 
Join Date: Oct 2004
Location: taking notes on u (see profile)
Posts: 13,492
Re: Coursera SaaS class (Ruby+Rails) discussion

Quote:
Originally Posted by candybar View Post
Cucumber was kind of fun to learn and somewhat cute but is this really useful? Why use a language whose best feature is resemblance to English to write tests, if you have to use regex to extend/parse the language anyhow?
apparently this is a real debate, with DHH taking your side:
http://www.rubyinside.com/dhh-offend...bate-4610.html

i enjoyed this exchange quoted in the article:



gaming_mouse is offline   Reply With Quote
Old 03-20-2012, 01:39 PM   #35
clowntable
Carpal \'Tunnel
 
clowntable's Avatar
 
Join Date: Jun 2006
Location: 39, 46, 56, 59, 191
Posts: 45,289
Re: Coursera SaaS class (Ruby+Rails) discussion

"Why would you build a test-specific parser for English" is such a silly question.
Spoiler:
clowntable is offline   Reply With Quote
Old 03-20-2012, 03:13 PM   #36
candybar
old hand
 
Join Date: Aug 2011
Posts: 1,357
Re: Coursera SaaS class (Ruby+Rails) discussion

Quote:
Originally Posted by gaming_mouse View Post
apparently this is a real debate, with DHH taking your side:
http://www.rubyinside.com/dhh-offend...bate-4610.html

i enjoyed this exchange quoted in the article:



LOL. I sort of get it now - feature files can be read and/or written by business folks, whether clients or product managers. And having to parse the feature files to test forces feature documentation to be maintained because tests will fail otherwise. An interesting, fun way to force people who speak different languages to work together. I can see where it may be worth the overhead.
candybar is offline   Reply With Quote
Old 03-21-2012, 01:01 AM   #37
jfresh
adept
 
jfresh's Avatar
 
Join Date: Sep 2003
Location: San Francisco
Posts: 1,113
Re: Coursera SaaS class (Ruby+Rails) discussion

Anyone have some ideas on how to write the rspec tests for this week's homework? Particularly:
-a RESTful route for Find Similar Movies
-handling the sad path of "no director"
I'm still having a hard time wrapping my head around stubbing/isolating functionalities in rspec in general, I think.

Also, it sounds like the hw is saying you should re-use the show.html.haml page for when the user clicks 'Find similar movies'- how are people adding functionality to that page for multiple movies? I implemented it one way but seems kind of clunky.
jfresh is offline   Reply With Quote
Old 03-30-2012, 04:26 PM   #38
Mariogs379
adept
 
Join Date: Jun 2005
Posts: 1,066
Re: Coursera SaaS class (Ruby+Rails) discussion

Quick question on getting setup with Ruby: I downloaded/installed but am a little confused. I can open "Interactive Ruby" and it looks similar to command prompt but think I'm doing something wrong. I'm trying to follow along here:

http://pine.fm/LearnToProgram/?Chapter=00

Not clear how to save the program you write if I'm doing it right. Having said that, I can't write multiple lines of code and then run the program...so I feel like I'm not looking in the right place.

Thanks for the help guys,
Mariogs
Mariogs379 is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Forum Jump


All times are GMT -4. The time now is 05:03 PM.


Powered by vBulletin®
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.
Search Engine Optimisation provided by DragonByte SEO v2.0.33 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Copyright ę 2008-2010, Two Plus Two Interactive
 
 
Poker Players - Streaming Live Online