From f4357fb080cdc9a07f738f85a05e6bdd05be86ad Mon Sep 17 00:00:00 2001 From: Adriana Date: Mon, 7 Mar 2016 16:52:42 -0800 Subject: [PATCH 01/39] Added all necessary files --- .ruby-gemset | 1 + .ruby-version | 1 + lib/player.rb | 0 lib/scoring.rb | 0 scrabble.rb | 0 spec/player-spec.rb | 0 spec/scoring-spec.rb | 0 7 files changed, 2 insertions(+) create mode 100644 .ruby-gemset create mode 100644 .ruby-version create mode 100644 lib/player.rb create mode 100644 lib/scoring.rb create mode 100644 scrabble.rb create mode 100644 spec/player-spec.rb create mode 100644 spec/scoring-spec.rb diff --git a/.ruby-gemset b/.ruby-gemset new file mode 100644 index 00000000..f24df478 --- /dev/null +++ b/.ruby-gemset @@ -0,0 +1 @@ +scrabble diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 00000000..276cbf9e --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.3.0 diff --git a/lib/player.rb b/lib/player.rb new file mode 100644 index 00000000..e69de29b diff --git a/lib/scoring.rb b/lib/scoring.rb new file mode 100644 index 00000000..e69de29b diff --git a/scrabble.rb b/scrabble.rb new file mode 100644 index 00000000..e69de29b diff --git a/spec/player-spec.rb b/spec/player-spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/spec/scoring-spec.rb b/spec/scoring-spec.rb new file mode 100644 index 00000000..e69de29b From 8a27d61179b93173f9cd86e29f67793e2725ec4e Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Tue, 8 Mar 2016 10:12:05 -0800 Subject: [PATCH 02/39] Shaving Yaks! AKA, more setup. --- Rakefile | 9 +++++++++ lib/scoring.rb | 1 + scrabble.rb | 7 +++++++ spec/scoring-spec.rb | 8 ++++++++ spec/spec_helper.rb | 10 ++++++++++ 5 files changed, 35 insertions(+) create mode 100644 Rakefile create mode 100644 spec/spec_helper.rb diff --git a/Rakefile b/Rakefile new file mode 100644 index 00000000..4c0a9830 --- /dev/null +++ b/Rakefile @@ -0,0 +1,9 @@ +require 'rake/testtask' + +Rake::TestTask.new do |t| + t.libs = ["lib"] + t.warning = true + t.test_files = FileList['spec/*-spec.rb'] +end + +task default: :test diff --git a/lib/scoring.rb b/lib/scoring.rb index e69de29b..7f159b13 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -0,0 +1 @@ +puts "butts" diff --git a/scrabble.rb b/scrabble.rb index e69de29b..f419d8bf 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -0,0 +1,7 @@ +module Scrabble + class Scoring + end + + class Player + end +end diff --git a/spec/scoring-spec.rb b/spec/scoring-spec.rb index e69de29b..0617ce2f 100644 --- a/spec/scoring-spec.rb +++ b/spec/scoring-spec.rb @@ -0,0 +1,8 @@ +require_relative './spec_helper' +require_relative '../lib/scoring' + +describe Scoring do + it "if it exists" do + Scoring.wont_be_nil + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 00000000..3950a123 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,10 @@ +require 'simplecov' +SimpleCov.start + +require 'minitest' +require 'minitest/spec' +require 'minitest/autorun' +require 'minitest/reporters' + +# give us some really pretty output :) +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 6ac0e09a05d0812adcc266fe930458d931244618 Mon Sep 17 00:00:00 2001 From: Adriana Date: Tue, 8 Mar 2016 10:55:47 -0800 Subject: [PATCH 03/39] Updated tests to include score method --- lib/scoring.rb | 7 ++++++- scrabble.rb | 4 ++++ spec/scoring-spec.rb | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 7f159b13..335da141 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -1 +1,6 @@ -puts "butts" +class Scoring + def self.score + return "hello world" + end + +end diff --git a/scrabble.rb b/scrabble.rb index f419d8bf..7caba072 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -1,5 +1,9 @@ +require 'lib/scoring.rb' +require 'lib/player.rb' + module Scrabble class Scoring + end class Player diff --git a/spec/scoring-spec.rb b/spec/scoring-spec.rb index 0617ce2f..15cc767d 100644 --- a/spec/scoring-spec.rb +++ b/spec/scoring-spec.rb @@ -5,4 +5,10 @@ it "if it exists" do Scoring.wont_be_nil end + + describe Scoring.score do + it "if it exists" do + Scoring.score.wont_be_nil + end + end end From 14ab14edf1ff1afb78618aeae674dd26448dfa08 Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Tue, 8 Mar 2016 11:33:14 -0800 Subject: [PATCH 04/39] Discovered octothorp necessity in calling methods with tdd. Tests are passing currently. Added scoring constants within the self.score(word) method test, still need to add them in the scoring class itself. --- lib/scoring.rb | 8 +++++--- scrabble.rb | 1 - spec/scoring-spec.rb | 15 +++++++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 335da141..06c1e3a3 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -1,6 +1,8 @@ class Scoring - def self.score - return "hello world" - end + + + def self.score(word) + word + end end diff --git a/scrabble.rb b/scrabble.rb index 7caba072..5c888d9d 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -3,7 +3,6 @@ module Scrabble class Scoring - end class Player diff --git a/spec/scoring-spec.rb b/spec/scoring-spec.rb index 15cc767d..920aea68 100644 --- a/spec/scoring-spec.rb +++ b/spec/scoring-spec.rb @@ -6,9 +6,20 @@ Scoring.wont_be_nil end - describe Scoring.score do + describe "Scoring#score(word)" do it "if it exists" do - Scoring.score.wont_be_nil + "Scoring#score(word).wont_be_nil" end + + SCORE_CHART = { + a, e, i, o, u, l, n, r, s, t => 1, + d, g => 2, + b, c, m, p => 3, + f, h, v, w, y => 4, + k => 5, + j, x => 8, + q, z => 10 + } + end end From 3b71c0c712dc4af0e51d080d23a2d5dbbbf24877 Mon Sep 17 00:00:00 2001 From: Adriana Date: Tue, 8 Mar 2016 14:00:55 -0800 Subject: [PATCH 05/39] updated our TDD to pass in a word and see if the word is split. Made our code return an array of characters. Tests pass. --- lib/scoring.rb | 14 +++++++++++--- spec/scoring-spec.rb | 25 ++++++++++++++++--------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 06c1e3a3..127d76a0 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -1,8 +1,16 @@ class Scoring - - + # SCORE_CHART = [ + # [a, e, i, o, u, l, n, r, s, t = 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + # [d, g = 2, 2], + # [b, c, m, p = 3, 3, 3, 3], + # [f, h, v, w, y = 4, 4, 4, 4, 4], + # [k = 5], + # [j, x = 8, 8], + # [q, z = 10, 10] + # ] def self.score(word) - word + arr = word.split(//) + return arr end end diff --git a/spec/scoring-spec.rb b/spec/scoring-spec.rb index 920aea68..bfb1ce3a 100644 --- a/spec/scoring-spec.rb +++ b/spec/scoring-spec.rb @@ -11,15 +11,22 @@ "Scoring#score(word).wont_be_nil" end - SCORE_CHART = { - a, e, i, o, u, l, n, r, s, t => 1, - d, g => 2, - b, c, m, p => 3, - f, h, v, w, y => 4, - k => 5, - j, x => 8, - q, z => 10 - } + # SCORE_CHART = [ + # [a, e, i, o, u, l, n, r, s, t = 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + # [d, g = 2, 2], + # [b, c, m, p = 3, 3, 3, 3], + # [f, h, v, w, y = 4, 4, 4, 4, 4], + # [k = 5], + # [j, x = 8, 8], + # [q, z = 10, 10] + # ] + + describe "Scoring#score(word)" do + it "Does it split the word into an array" do + assert Scoring.score("word") == ["w", "o", "r", "d"] + return + end + end end end From e0a32d0c471c3110fa039905a9bfe2dac729d81d Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Tue, 8 Mar 2016 14:24:38 -0800 Subject: [PATCH 06/39] Added scoring chart hash, and test cases hash. Began working on test to pull each letter from array and give it a score value. --- lib/scoring.rb | 20 ++++++++++---------- spec/scoring-spec.rb | 36 ++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 127d76a0..0d0a516e 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -1,16 +1,16 @@ class Scoring - # SCORE_CHART = [ - # [a, e, i, o, u, l, n, r, s, t = 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - # [d, g = 2, 2], - # [b, c, m, p = 3, 3, 3, 3], - # [f, h, v, w, y = 4, 4, 4, 4, 4], - # [k = 5], - # [j, x = 8, 8], - # [q, z = 10, 10] - # ] + SCORE_CHART = { + a => 1, e => 1, i => 1, o => 1, u => 1, l => 1, n => 1, r => 1, s => 1, t => 1, + d => 2, g => 2, + b => 3, c => 3, m => 3, p => 3, + f => 4, h => 4, v => 4, w => 4, y => 4, + k => 5, + j => 8, x => 8, + q => 10, z => 10 + } def self.score(word) arr = word.split(//) - return arr + return arr end end diff --git a/spec/scoring-spec.rb b/spec/scoring-spec.rb index bfb1ce3a..a4ea878b 100644 --- a/spec/scoring-spec.rb +++ b/spec/scoring-spec.rb @@ -11,16 +11,6 @@ "Scoring#score(word).wont_be_nil" end - # SCORE_CHART = [ - # [a, e, i, o, u, l, n, r, s, t = 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - # [d, g = 2, 2], - # [b, c, m, p = 3, 3, 3, 3], - # [f, h, v, w, y = 4, 4, 4, 4, 4], - # [k = 5], - # [j, x = 8, 8], - # [q, z = 10, 10] - # ] - describe "Scoring#score(word)" do it "Does it split the word into an array" do assert Scoring.score("word") == ["w", "o", "r", "d"] @@ -28,5 +18,31 @@ end end + describe "Scoring#score(word)" do + it "Does it split the word into an array" do + assert Scoring.score("google") == ["g", "o", "o", "g", "l", "e"] + return + end + end + + describe "Scoring#score" do + it "Does it assign a score number to each letter" do + TEST_CASES = { + a => 1, + e => 1, + u => 1, + d => 2, + b => 3, + m => 3, + f => 4, + v => 4, + k => 5, + j => 8, + z => 10 + } + + end + end + end end From 1dcaea855b25f1cb2fa3fbfccdc819f8f7b87e5f Mon Sep 17 00:00:00 2001 From: Adriana Date: Tue, 8 Mar 2016 14:49:46 -0800 Subject: [PATCH 07/39] Wrote out loop to test all of our test cases. Started making our code do what our test case wants --- lib/scoring.rb | 7 ++++++- spec/scoring-spec.rb | 36 +++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 0d0a516e..5ffe233b 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -11,6 +11,11 @@ class Scoring def self.score(word) arr = word.split(//) - return arr + arr.length.each do |i| + if arr[i] = + end + end + + end end diff --git a/spec/scoring-spec.rb b/spec/scoring-spec.rb index a4ea878b..870ddeb7 100644 --- a/spec/scoring-spec.rb +++ b/spec/scoring-spec.rb @@ -21,28 +21,30 @@ describe "Scoring#score(word)" do it "Does it split the word into an array" do assert Scoring.score("google") == ["g", "o", "o", "g", "l", "e"] - return end end - describe "Scoring#score" do - it "Does it assign a score number to each letter" do - TEST_CASES = { - a => 1, - e => 1, - u => 1, - d => 2, - b => 3, - m => 3, - f => 4, - v => 4, - k => 5, - j => 8, - z => 10 - } + describe "Scoring#score(word)" do + # Scoring.score("google") == ["g", "o", "o", "g", "l", "e"] + TEST_CASES = { + a => 1, + e => 1, + u => 1, + d => 2, + b => 3, + m => 3, + f => 4, + v => 4, + k => 5, + j => 8, + z => 10 + } + TEST_CASES.each do |letters, score| + it "Does it assign a score number to each letter" do + Scoring.score(letters).must_equal(score) + end end end - end end From fee88433b9c41823f1dd4330aebe0a1e1155539e Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Tue, 8 Mar 2016 15:27:13 -0800 Subject: [PATCH 08/39] Now that we are certain that the split portion of our score method is working we have removed the tests asserting the split. We have moved on to making the score method start to actually score the letters in the array we have made. Currently, there is some jerk code up in there. --- lib/scoring.rb | 21 ++++++++++----------- spec/scoring-spec.rb | 35 +++++++++++------------------------ 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 5ffe233b..a8296140 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -1,21 +1,20 @@ class Scoring SCORE_CHART = { - a => 1, e => 1, i => 1, o => 1, u => 1, l => 1, n => 1, r => 1, s => 1, t => 1, - d => 2, g => 2, - b => 3, c => 3, m => 3, p => 3, - f => 4, h => 4, v => 4, w => 4, y => 4, - k => 5, - j => 8, x => 8, - q => 10, z => 10 + "a" => 1, "e" => 1, "i" => 1, "o" => 1, "u" => 1, "l" => 1, "n" => 1, "r" => 1, "s" => 1, "t" => 1, + "d" => 2, "g" => 2, + "b" => 3, "c" => 3, "m" => 3, "p" => 3, + "f" => 4, "h" => 4, "v" => 4, "w" => 4, "y" => 4, + "k" => 5, + "j" => 8, "x" => 8, + "q" => 10, "z" => 10 } def self.score(word) arr = word.split(//) - arr.length.each do |i| - if arr[i] = + arr.each do |i| + if "a" + return 1 end end - - end end diff --git a/spec/scoring-spec.rb b/spec/scoring-spec.rb index 870ddeb7..2d61efa8 100644 --- a/spec/scoring-spec.rb +++ b/spec/scoring-spec.rb @@ -11,33 +11,20 @@ "Scoring#score(word).wont_be_nil" end - describe "Scoring#score(word)" do - it "Does it split the word into an array" do - assert Scoring.score("word") == ["w", "o", "r", "d"] - return - end - end - - describe "Scoring#score(word)" do - it "Does it split the word into an array" do - assert Scoring.score("google") == ["g", "o", "o", "g", "l", "e"] - end - end - describe "Scoring#score(word)" do # Scoring.score("google") == ["g", "o", "o", "g", "l", "e"] TEST_CASES = { - a => 1, - e => 1, - u => 1, - d => 2, - b => 3, - m => 3, - f => 4, - v => 4, - k => 5, - j => 8, - z => 10 + "a" => 1, + # "e" => 1, + # "u" => 1, + # "d" => 2, + # "b" => 3, + # "m" => 3, + # "f" => 4, + # "v" => 4, + # "k" => 5, + # "j" => 8, + # "z" => 10 } TEST_CASES.each do |letters, score| From 91a7fe00f47ba7522645ff61252849bbc61280e6 Mon Sep 17 00:00:00 2001 From: Adriana Date: Tue, 8 Mar 2016 15:56:09 -0800 Subject: [PATCH 09/39] Made a loop in scoring.rb that goes through each letter and assigns a score. Modified scoring-spec.rb to test out different cases. --- lib/scoring.rb | 5 ++--- spec/scoring-spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index a8296140..e344c0b3 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -12,9 +12,8 @@ class Scoring def self.score(word) arr = word.split(//) arr.each do |i| - if "a" - return 1 - end + jerk = SCORE_CHART[i] + return jerk end end end diff --git a/spec/scoring-spec.rb b/spec/scoring-spec.rb index 2d61efa8..b41043f4 100644 --- a/spec/scoring-spec.rb +++ b/spec/scoring-spec.rb @@ -15,10 +15,10 @@ # Scoring.score("google") == ["g", "o", "o", "g", "l", "e"] TEST_CASES = { "a" => 1, - # "e" => 1, + #{}"e" => 1, # "u" => 1, # "d" => 2, - # "b" => 3, + "b" => 3, # "m" => 3, # "f" => 4, # "v" => 4, From 62acc10da81fe6ca0d2d8d8eccb2194c6b4e7227 Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Tue, 8 Mar 2016 16:27:21 -0800 Subject: [PATCH 10/39] YAY! Score method now adds the letter values. --- lib/scoring.rb | 6 ++++-- spec/scoring-spec.rb | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index e344c0b3..70cd5bf7 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -10,10 +10,12 @@ class Scoring } def self.score(word) + tally = 0 arr = word.split(//) arr.each do |i| - jerk = SCORE_CHART[i] - return jerk + value = SCORE_CHART[i] + tally = value + tally end + return tally end end diff --git a/spec/scoring-spec.rb b/spec/scoring-spec.rb index b41043f4..6ded6a76 100644 --- a/spec/scoring-spec.rb +++ b/spec/scoring-spec.rb @@ -12,13 +12,13 @@ end describe "Scoring#score(word)" do - # Scoring.score("google") == ["g", "o", "o", "g", "l", "e"] TEST_CASES = { - "a" => 1, - #{}"e" => 1, + "cat" => 5 + # "a" => 1, + # "e" => 1, # "u" => 1, # "d" => 2, - "b" => 3, + # "b" => 3, # "m" => 3, # "f" => 4, # "v" => 4, From 5fd0c0540227cf9e78a870eb14cb104bd773eae6 Mon Sep 17 00:00:00 2001 From: Adriana Date: Tue, 8 Mar 2016 16:45:12 -0800 Subject: [PATCH 11/39] Added te 50 point bonus. Added a ternary conditional. Updated tests to grow with our code. Made all letters downcase so case is not an issue --- lib/scoring.rb | 4 ++-- spec/scoring-spec.rb | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 70cd5bf7..bc5488a9 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -10,8 +10,8 @@ class Scoring } def self.score(word) - tally = 0 - arr = word.split(//) + arr = word.downcase.split(//) + arr.length == 7 ? tally = 50 : tally = 0 arr.each do |i| value = SCORE_CHART[i] tally = value + tally diff --git a/spec/scoring-spec.rb b/spec/scoring-spec.rb index 6ded6a76..3de849c3 100644 --- a/spec/scoring-spec.rb +++ b/spec/scoring-spec.rb @@ -13,12 +13,12 @@ describe "Scoring#score(word)" do TEST_CASES = { - "cat" => 5 - # "a" => 1, - # "e" => 1, - # "u" => 1, - # "d" => 2, - # "b" => 3, + "cat" => 5, + "CAT" => 5, + "BOX" => 12, + "box" => 12, + "googles" => 59, + "GOOgles" => 59 # "m" => 3, # "f" => 4, # "v" => 4, From 42f8e55b8c8c45b963ee3b9ab465b7e217b9f95e Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Tue, 8 Mar 2016 17:15:51 -0800 Subject: [PATCH 12/39] Removed 'if it exists' tests as we do not need them. Started work on highest_score_from(word_array) method. --- lib/scoring.rb | 4 ++++ spec/scoring-spec.rb | 48 +++++++++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index bc5488a9..85b42550 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -18,4 +18,8 @@ def self.score(word) end return tally end + + def self.highest_score_from(array_of_words) + Scoring::score(array_of_words) + end end diff --git a/spec/scoring-spec.rb b/spec/scoring-spec.rb index 3de849c3..23fa697f 100644 --- a/spec/scoring-spec.rb +++ b/spec/scoring-spec.rb @@ -7,30 +7,36 @@ end describe "Scoring#score(word)" do - it "if it exists" do - "Scoring#score(word).wont_be_nil" + HASH_CASES = { + "cat" => 5, + "CAT" => 5, + "BOX" => 12, + "box" => 12, + "googles" => 59, + "GOOgles" => 59 + # "m" => 3, + # "f" => 4, + # "v" => 4, + # "k" => 5, + # "j" => 8, + # "z" => 10 + } + + HASH_CASES.each do |letters, score| + it "Does it assign a score number to each letter" do + Scoring.score(letters).must_equal(score) + end end + end - describe "Scoring#score(word)" do - TEST_CASES = { - "cat" => 5, - "CAT" => 5, - "BOX" => 12, - "box" => 12, - "googles" => 59, - "GOOgles" => 59 - # "m" => 3, - # "f" => 4, - # "v" => 4, - # "k" => 5, - # "j" => 8, - # "z" => 10 - } + describe "Scoring#highest_score_from(array_of_words)" do + ARRAY_CASES = [ + "cat", "box"#, "phone", "butts", "purple", "farts", "hands" + ] - TEST_CASES.each do |letters, score| - it "Does it assign a score number to each letter" do - Scoring.score(letters).must_equal(score) - end + ARRAY_CASES.each do |array_word| + it "Does it return the highest score" do + Scoring.highest_score_from(array_word).max end end end From c4454f31245bd9c68d766fe4242b0c606c9d2935 Mon Sep 17 00:00:00 2001 From: Adriana Date: Wed, 9 Mar 2016 09:58:35 -0800 Subject: [PATCH 13/39] Updated scoring-spec so that ARRAY_CASES contained hashes. Made sure that it had a key value pair that was passed to the test. In lib/scoring.rb, we updated the code to run it with the simplest case of returning the word with the highest score. --- lib/scoring.rb | 11 ++++++++++- spec/scoring-spec.rb | 17 ++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 85b42550..2c220dc1 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -20,6 +20,15 @@ def self.score(word) end def self.highest_score_from(array_of_words) - Scoring::score(array_of_words) + high_words = "" + high_score = 0 + array_of_words.each do |word| + self.score(word) + if self.score(word) > high_score + high_words = word + high_score = self.score(word) + end + end + return high_words end end diff --git a/spec/scoring-spec.rb b/spec/scoring-spec.rb index 23fa697f..870ce63b 100644 --- a/spec/scoring-spec.rb +++ b/spec/scoring-spec.rb @@ -30,13 +30,20 @@ end describe "Scoring#highest_score_from(array_of_words)" do - ARRAY_CASES = [ - "cat", "box"#, "phone", "butts", "purple", "farts", "hands" - ] + ARRAY_CASES = { + "cat" => ["cat"] + # "box" => ["cat", "box"], + # "box" => ["phone", "box", "cat"], + # "purple" => ["purple", "farts", "hands", "butts"], + # "hands" => ["hands", "violet"], + # "hands" => ["violet", "hands"], + # "jukebox" => ["jukebox", "cazique", "mezquit"], + # "buzzcut" => ["jukebox", "buzzcut"] + } - ARRAY_CASES.each do |array_word| + ARRAY_CASES.each do |key, value| it "Does it return the highest score" do - Scoring.highest_score_from(array_word).max + Scoring.highest_score_from(value).must_equal(key) end end end From 5ad6fced5d794317ea297664e7168824a3274f63 Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Wed, 9 Mar 2016 10:26:01 -0800 Subject: [PATCH 14/39] Added back in scoring test cases for single letters, as they are still good working tests. Completed work on our highest_scoring_word method, to include the requirement for the top scoring 7 letter word to be the returned value, as well as the FIRST instance of a 7 letter word tie to be returned. --- lib/scoring.rb | 11 ++++++++--- spec/scoring-spec.rb | 32 +++++++++++++++++--------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 2c220dc1..0f0f10f4 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -20,15 +20,20 @@ def self.score(word) end def self.highest_score_from(array_of_words) - high_words = "" + high_word = "" high_score = 0 array_of_words.each do |word| self.score(word) if self.score(word) > high_score - high_words = word + high_word = word high_score = self.score(word) + elsif self.score(word) == high_score + if word.length < high_word.length + high_word = word + high_score = self.score(word) + end end end - return high_words + return high_word end end diff --git a/spec/scoring-spec.rb b/spec/scoring-spec.rb index 870ce63b..0b62a283 100644 --- a/spec/scoring-spec.rb +++ b/spec/scoring-spec.rb @@ -13,13 +13,13 @@ "BOX" => 12, "box" => 12, "googles" => 59, - "GOOgles" => 59 - # "m" => 3, - # "f" => 4, - # "v" => 4, - # "k" => 5, - # "j" => 8, - # "z" => 10 + "GOOgles" => 59, + "m" => 3, + "f" => 4, + "v" => 4, + "k" => 5, + "j" => 8, + "z" => 10 } HASH_CASES.each do |letters, score| @@ -31,14 +31,16 @@ describe "Scoring#highest_score_from(array_of_words)" do ARRAY_CASES = { - "cat" => ["cat"] - # "box" => ["cat", "box"], - # "box" => ["phone", "box", "cat"], - # "purple" => ["purple", "farts", "hands", "butts"], - # "hands" => ["hands", "violet"], - # "hands" => ["violet", "hands"], - # "jukebox" => ["jukebox", "cazique", "mezquit"], - # "buzzcut" => ["jukebox", "buzzcut"] + "cat" => ["cat"], + "box" => ["cat", "box"], + "box" => ["phone", "box", "cat"], + "purple" => ["purple", "farts", "hands", "butts"], + "hands" => ["hands", "violet"], + "hands" => ["violet", "hands"], + "jukebox" => ["jukebox", "cazique", "mezquit"], + "mezquit" => ["mezquit", "jukebox", "cazique"], + "buzzcut" => ["jukebox", "buzzcut"], + "buzzcut" => ["buzzcut", "jukebox"] } ARRAY_CASES.each do |key, value| From 7e5b99b4a948c52c8d853d6f3a698c48682aa4c2 Mon Sep 17 00:00:00 2001 From: Adriana Date: Wed, 9 Mar 2016 16:14:27 -0800 Subject: [PATCH 15/39] Changed error message in scoring-spec. Started tests in player-spec and started writing code in player.rb --- lib/player.rb | 7 +++++++ spec/player-spec.rb | 15 +++++++++++++++ spec/scoring-spec.rb | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/player.rb b/lib/player.rb index e69de29b..c55bae60 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -0,0 +1,7 @@ +class Player + def initialize + + end + + +end diff --git a/spec/player-spec.rb b/spec/player-spec.rb index e69de29b..bc551b9d 100644 --- a/spec/player-spec.rb +++ b/spec/player-spec.rb @@ -0,0 +1,15 @@ +require_relative './spec_helper' +require_relative '../lib/player' + +describe Player do + it "Does the Player Class exist test?" do + Player.wont_be_nil + end + + describe "Player#new" do + it "Does the class initialize with a name" do + self.new.wont_be_nil + end + + end +end diff --git a/spec/scoring-spec.rb b/spec/scoring-spec.rb index 0b62a283..504ddd1f 100644 --- a/spec/scoring-spec.rb +++ b/spec/scoring-spec.rb @@ -2,7 +2,7 @@ require_relative '../lib/scoring' describe Scoring do - it "if it exists" do + it "Does the Scoring Class exist?" do Scoring.wont_be_nil end From c1dcba25c0d73a863027fa33fb1421520ebee1ed Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Wed, 9 Mar 2016 16:39:58 -0800 Subject: [PATCH 16/39] Added name instance, and test for name instance being returned. Added plays method, tested if it exists, and started next test for it to actually do something. --- lib/player.rb | 7 +++++-- spec/player-spec.rb | 13 +++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index c55bae60..64dc9697 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -1,7 +1,10 @@ class Player - def initialize - + attr_reader :name + def initialize(name) + @name = name end + def self.plays + end end diff --git a/spec/player-spec.rb b/spec/player-spec.rb index bc551b9d..568a52f2 100644 --- a/spec/player-spec.rb +++ b/spec/player-spec.rb @@ -6,10 +6,19 @@ Player.wont_be_nil end - describe "Player#new" do + describe "Player#new(name)" do it "Does the class initialize with a name" do - self.new.wont_be_nil + Player.new(name).wont_be_nil + end + end + + describe "Player#plays" do + it "Does it exist" do + "Player#plays.wont_be_nil" end + it "returns an array of the words played by the player" do + "Player#plays.wont_be_nil" + end end end From dd2426dd1cc0451d1b89e03583ae06c39ead4489 Mon Sep 17 00:00:00 2001 From: Adriana Date: Wed, 9 Mar 2016 16:59:33 -0800 Subject: [PATCH 17/39] Added extra tests to make sure all our methods would be there. Started researching assert_not_nil. Trying to get tests to fail since not existing yet --- spec/player-spec.rb | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/spec/player-spec.rb b/spec/player-spec.rb index 568a52f2..2a7e09a9 100644 --- a/spec/player-spec.rb +++ b/spec/player-spec.rb @@ -14,11 +14,47 @@ describe "Player#plays" do it "Does it exist" do - "Player#plays.wont_be_nil" + assert_nil(Player.plays, failure_message = nil) end - it "returns an array of the words played by the player" do + # it "returns an array of the words played by the player" do + # assert Player.plays.include?([]) + # end + end + + describe "Player#plays" do + it "Does it exist plays" do "Player#plays.wont_be_nil" end end + + describe "Player#play(word)" do + it "Does it exist play(word)" do + "Player#play(name).wont_be_nil" + end + end + + describe "Player#total_score" do + it "Does it exist total_score" do + "Player#total_score.wont_be_nil" + end + end + + describe "Player#won?" do + it "Does it exist won?" do + "Player#won?.wont_be_nil" + end + end + + describe "Player#highest_scoring_word" do + it "Does it exist highest_scoring_word?" do + "Player#highest_scoring_word.wont_be_nil" + end + end + + describe "Player#highest_word_score?" do + it "Does it exist highest_word_score" do + "Player#highest_word_score.wont_be_nil" + end + end end From adaa5ee6d0fd048c814a1f7a8c64fe49ed709e20 Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Thu, 10 Mar 2016 13:02:47 -0800 Subject: [PATCH 18/39] Working on plays method, seeing if it returns an array. --- spec/player-spec.rb | 80 ++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/spec/player-spec.rb b/spec/player-spec.rb index 2a7e09a9..cdb869ab 100644 --- a/spec/player-spec.rb +++ b/spec/player-spec.rb @@ -13,48 +13,54 @@ end describe "Player#plays" do - it "Does it exist" do - assert_nil(Player.plays, failure_message = nil) + it "Does it contain an array" do + end - - # it "returns an array of the words played by the player" do - # assert Player.plays.include?([]) - # end end +end - describe "Player#plays" do - it "Does it exist plays" do - "Player#plays.wont_be_nil" - end - end - describe "Player#play(word)" do - it "Does it exist play(word)" do - "Player#play(name).wont_be_nil" - end - end - describe "Player#total_score" do - it "Does it exist total_score" do - "Player#total_score.wont_be_nil" - end - end - describe "Player#won?" do - it "Does it exist won?" do - "Player#won?.wont_be_nil" - end - end - describe "Player#highest_scoring_word" do - it "Does it exist highest_scoring_word?" do - "Player#highest_scoring_word.wont_be_nil" - end - end - describe "Player#highest_word_score?" do - it "Does it exist highest_word_score" do - "Player#highest_word_score.wont_be_nil" - end - end -end + # it "returns an array of the words played by the player" do + # assert Player.plays.include?([]) + # end + # end + + # describe "Player#plays" do + # it "Does the 'plays' method exist" do + # Player.plays.wont_be_nil + # end + # end + # + # describe "Player#play(word)" do + # it "Does the play(word) method exist" do + # "Player#play(name).wont_be_nil" + # end + # end + # + # describe "Player#total_score" do + # it "Does the total_score method exist" do + # "Player#total_score.wont_be_nil" + # end + # end + # + # describe "Player#won?" do + # it "Does the won? method exist" do + # "Player#won?.wont_be_nil" + # end + # end + # + # describe "Player#highest_scoring_word" do + # it "Does the highest_scoring_word method exist" do + # "Player#highest_scoring_word.wont_be_nil" + # end + # end + # + # describe "Player#highest_word_score?" do + # it "Does the highest_word_score method exist" do + # "Player#highest_word_score.wont_be_nil" + # end + # end From 6864903fe9fd6b115eb2455bcc98990e3cfc4b15 Mon Sep 17 00:00:00 2001 From: Adriana Date: Thu, 10 Mar 2016 13:25:27 -0800 Subject: [PATCH 19/39] Tested and changed code to see if we can check if our plays method returns on array --- lib/player.rb | 4 +-- spec/player-spec.rb | 88 +++++++++++++++++++++++---------------------- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 64dc9697..98dedb65 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -4,7 +4,7 @@ def initialize(name) @name = name end - def self.plays - + def plays + "hello" end end diff --git a/spec/player-spec.rb b/spec/player-spec.rb index cdb869ab..cd458560 100644 --- a/spec/player-spec.rb +++ b/spec/player-spec.rb @@ -12,9 +12,13 @@ end end - describe "Player#plays" do - it "Does it contain an array" do - + before do + jillian = Player.new(name) + + describe "#plays" do + it "Does it contain an array" do + jillian.plays.must_be_kind_of Array + end end end end @@ -24,43 +28,43 @@ - # it "returns an array of the words played by the player" do - # assert Player.plays.include?([]) - # end - # end +# it "returns an array of the words played by the player" do +# assert Player.plays.include?([]) +# end +# end - # describe "Player#plays" do - # it "Does the 'plays' method exist" do - # Player.plays.wont_be_nil - # end - # end - # - # describe "Player#play(word)" do - # it "Does the play(word) method exist" do - # "Player#play(name).wont_be_nil" - # end - # end - # - # describe "Player#total_score" do - # it "Does the total_score method exist" do - # "Player#total_score.wont_be_nil" - # end - # end - # - # describe "Player#won?" do - # it "Does the won? method exist" do - # "Player#won?.wont_be_nil" - # end - # end - # - # describe "Player#highest_scoring_word" do - # it "Does the highest_scoring_word method exist" do - # "Player#highest_scoring_word.wont_be_nil" - # end - # end - # - # describe "Player#highest_word_score?" do - # it "Does the highest_word_score method exist" do - # "Player#highest_word_score.wont_be_nil" - # end - # end +# describe "Player#plays" do +# it "Does the 'plays' method exist" do +# Player.plays.wont_be_nil +# end +# end +# +# describe "Player#play(word)" do +# it "Does the play(word) method exist" do +# "Player#play(name).wont_be_nil" +# end +# end +# +# describe "Player#total_score" do +# it "Does the total_score method exist" do +# "Player#total_score.wont_be_nil" +# end +# end +# +# describe "Player#won?" do +# it "Does the won? method exist" do +# "Player#won?.wont_be_nil" +# end +# end +# +# describe "Player#highest_scoring_word" do +# it "Does the highest_scoring_word method exist" do +# "Player#highest_scoring_word.wont_be_nil" +# end +# end +# +# describe "Player#highest_word_score?" do +# it "Does the highest_word_score method exist" do +# "Player#highest_word_score.wont_be_nil" +# end +# end From 1ae1b7c23609c8b4f9399a687af1662769b0d0e1 Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Thu, 10 Mar 2016 13:58:06 -0800 Subject: [PATCH 20/39] Commented out passing tests from scoring-spec so that we had less to look at. Added an instance of player in order to finally call methods correctly. Started working on play(words) method, which will eventually push words into the array in plays method. --- lib/player.rb | 6 ++- spec/player-spec.rb | 28 ++++++++++--- spec/scoring-spec.rb | 98 ++++++++++++++++++++++---------------------- 3 files changed, 76 insertions(+), 56 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 98dedb65..8da0cfeb 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -5,6 +5,10 @@ def initialize(name) end def plays - "hello" + players_played_words = [] + return players_played_words + end + + def play(word) end end diff --git a/spec/player-spec.rb b/spec/player-spec.rb index cd458560..2c721033 100644 --- a/spec/player-spec.rb +++ b/spec/player-spec.rb @@ -12,19 +12,35 @@ end end - before do - jillian = Player.new(name) + describe "#plays" do + test_player = Player.new(name) + it "Does it contain an array" do + test_player.plays.must_be_kind_of Array + end + end + + describe "#play(word)" do + + test_player = Player.new(name) + + TEST_CASES = ["word", "butt", "fart", "red"] - describe "#plays" do - it "Does it contain an array" do - jillian.plays.must_be_kind_of Array + TEST_CASES.each do |word| + it "Does it add the played word?" do + test_player.play(word).must_equal(TEST_CASES) end end end end - +# describe "#plays" do +# test_player = Player.new(name) +# it "Does it return array of words played by player" do +# +# +# end +# end diff --git a/spec/scoring-spec.rb b/spec/scoring-spec.rb index 504ddd1f..1b47945a 100644 --- a/spec/scoring-spec.rb +++ b/spec/scoring-spec.rb @@ -1,52 +1,52 @@ require_relative './spec_helper' require_relative '../lib/scoring' -describe Scoring do - it "Does the Scoring Class exist?" do - Scoring.wont_be_nil - end - - describe "Scoring#score(word)" do - HASH_CASES = { - "cat" => 5, - "CAT" => 5, - "BOX" => 12, - "box" => 12, - "googles" => 59, - "GOOgles" => 59, - "m" => 3, - "f" => 4, - "v" => 4, - "k" => 5, - "j" => 8, - "z" => 10 - } - - HASH_CASES.each do |letters, score| - it "Does it assign a score number to each letter" do - Scoring.score(letters).must_equal(score) - end - end - end - - describe "Scoring#highest_score_from(array_of_words)" do - ARRAY_CASES = { - "cat" => ["cat"], - "box" => ["cat", "box"], - "box" => ["phone", "box", "cat"], - "purple" => ["purple", "farts", "hands", "butts"], - "hands" => ["hands", "violet"], - "hands" => ["violet", "hands"], - "jukebox" => ["jukebox", "cazique", "mezquit"], - "mezquit" => ["mezquit", "jukebox", "cazique"], - "buzzcut" => ["jukebox", "buzzcut"], - "buzzcut" => ["buzzcut", "jukebox"] - } - - ARRAY_CASES.each do |key, value| - it "Does it return the highest score" do - Scoring.highest_score_from(value).must_equal(key) - end - end - end -end +# describe Scoring do +# it "Does the Scoring Class exist?" do +# Scoring.wont_be_nil +# end +# +# describe "Scoring#score(word)" do +# HASH_CASES = { +# "cat" => 5, +# "CAT" => 5, +# "BOX" => 12, +# "box" => 12, +# "googles" => 59, +# "GOOgles" => 59, +# "m" => 3, +# "f" => 4, +# "v" => 4, +# "k" => 5, +# "j" => 8, +# "z" => 10 +# } +# +# HASH_CASES.each do |letters, score| +# it "Does it assign a score number to each letter" do +# Scoring.score(letters).must_equal(score) +# end +# end +# end +# +# describe "Scoring#highest_score_from(array_of_words)" do +# ARRAY_CASES = { +# "cat" => ["cat"], +# "box" => ["cat", "box"], +# "box" => ["phone", "box", "cat"], +# "purple" => ["purple", "farts", "hands", "butts"], +# "hands" => ["hands", "violet"], +# "hands" => ["violet", "hands"], +# "jukebox" => ["jukebox", "cazique", "mezquit"], +# "mezquit" => ["mezquit", "jukebox", "cazique"], +# "buzzcut" => ["jukebox", "buzzcut"], +# "buzzcut" => ["buzzcut", "jukebox"] +# } +# +# ARRAY_CASES.each do |key, value| +# it "Does it return the highest score" do +# Scoring.highest_score_from(value).must_equal(key) +# end +# end +# end +# end From dad7fae066f4bbcea9b02d8f1d8efac6e5dbdf05 Mon Sep 17 00:00:00 2001 From: Adriana Date: Thu, 10 Mar 2016 15:04:57 -0800 Subject: [PATCH 21/39] Created a new instance variable called @words that was set to an empty array so that we could push in a word that was used and save it in played words. Updated the play(word) method so that we can get the played words and then push it the plays method where we then store our words in an instance variable @words. --- lib/player.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 8da0cfeb..8d5b2f15 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -1,14 +1,16 @@ class Player - attr_reader :name + attr_reader :name, :word def initialize(name) @name = name + @words = [] end + def plays - players_played_words = [] - return players_played_words + @words end - + def play(word) + @words << word end end From 8eba8c611fbbf526b66c6756c08876adb5128a0d Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Thu, 10 Mar 2016 15:43:34 -0800 Subject: [PATCH 22/39] Got play(word) to push test case words to array contained within the plays method. Started work on the 'returns false if player has won' requirement. --- spec/player-spec.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/player-spec.rb b/spec/player-spec.rb index 2c721033..deb76760 100644 --- a/spec/player-spec.rb +++ b/spec/player-spec.rb @@ -25,11 +25,15 @@ TEST_CASES = ["word", "butt", "fart", "red"] - TEST_CASES.each do |word| + TEST_CASES.each do |played_word| it "Does it add the played word?" do - test_player.play(word).must_equal(TEST_CASES) + test_player.play(played_word).must_equal(test_player.plays) end end + + it "Does it return false if the player has won?" do + + end end end From d8f2fa9585c1e4d466cd3c9da12c95ad4938c09a Mon Sep 17 00:00:00 2001 From: Adriana Date: Thu, 10 Mar 2016 16:11:26 -0800 Subject: [PATCH 23/39] Added a new test that is also testing played(word) method, but also talking to the scoring.rb in the Scoring Class to get the score. Separated each test so they are their own fails. --- spec/player-spec.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/spec/player-spec.rb b/spec/player-spec.rb index deb76760..e705bd1e 100644 --- a/spec/player-spec.rb +++ b/spec/player-spec.rb @@ -1,6 +1,10 @@ require_relative './spec_helper' require_relative '../lib/player' +TEST_CASES = ["word", "butt", "fart", "red"] + + + describe Player do it "Does the Player Class exist test?" do Player.wont_be_nil @@ -23,16 +27,21 @@ test_player = Player.new(name) - TEST_CASES = ["word", "butt", "fart", "red"] - TEST_CASES.each do |played_word| it "Does it add the played word?" do test_player.play(played_word).must_equal(test_player.plays) end end + end - it "Does it return false if the player has won?" do - + describe "#play(word)" do + + test_player = Player.new(name) + + TEST_CASES.each do |played_word| + it "Does it return the score of the word" do + test_player.play(played_word).must_equal(Scoring.score(played_word)) + end end end end From 8a34bdd1b7b5a5df7bb39c726c51406720f97f38 Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Thu, 10 Mar 2016 16:56:51 -0800 Subject: [PATCH 24/39] corrected the test to test what we actually wanted to test, not the other way around. *facepalm* --- lib/player.rb | 4 ++++ spec/player-spec.rb | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 8d5b2f15..2855387a 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -3,14 +3,18 @@ class Player def initialize(name) @name = name @words = [] + @word_score = 0 end def plays @words + return @words end def play(word) + @word_score = Scoring.score(word) @words << word + return @word_score end end diff --git a/spec/player-spec.rb b/spec/player-spec.rb index e705bd1e..d481db23 100644 --- a/spec/player-spec.rb +++ b/spec/player-spec.rb @@ -27,11 +27,12 @@ test_player = Player.new(name) - TEST_CASES.each do |played_word| + # TEST_CASES.each do |played_word| it "Does it add the played word?" do - test_player.play(played_word).must_equal(test_player.plays) + test_player.play("word") + test_player.plays.must_equal(["word"]) end - end + # end end describe "#play(word)" do From 05db6b8bed7ad051c8a2175d292e36f1a0f8caaf Mon Sep 17 00:00:00 2001 From: Adriana Date: Fri, 11 Mar 2016 09:18:15 -0800 Subject: [PATCH 25/39] Took out an empty line --- lib/player.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/player.rb b/lib/player.rb index 2855387a..fc4b2de8 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -6,7 +6,6 @@ def initialize(name) @word_score = 0 end - def plays @words return @words From 86014849570ab6586b93f6073a4e0745addfaaa1 Mon Sep 17 00:00:00 2001 From: Adriana Date: Fri, 11 Mar 2016 09:53:29 -0800 Subject: [PATCH 26/39] Added a WIN_CONDITION --- lib/player.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/player.rb b/lib/player.rb index fc4b2de8..cc847b55 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -1,9 +1,12 @@ class Player attr_reader :name, :word + WIN_CONDITION = 100 + def initialize(name) @name = name @words = [] @word_score = 0 + end def plays From da71203c4da1f976ce9c43b73618a550157bd3c7 Mon Sep 17 00:00:00 2001 From: Adriana Date: Fri, 11 Mar 2016 10:13:29 -0800 Subject: [PATCH 27/39] Added the method total_score. Started the test for total score --- lib/player.rb | 4 +++ spec/player-spec.rb | 61 ++++++++------------------------------------- 2 files changed, 15 insertions(+), 50 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index cc847b55..66137f8e 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -19,4 +19,8 @@ def play(word) @words << word return @word_score end + + def total_score + + end end diff --git a/spec/player-spec.rb b/spec/player-spec.rb index d481db23..f60ed26c 100644 --- a/spec/player-spec.rb +++ b/spec/player-spec.rb @@ -45,56 +45,17 @@ end end end -end - - -# describe "#plays" do -# test_player = Player.new(name) -# it "Does it return array of words played by player" do -# -# -# end -# end + describe "#total_score" do + test_player = Player.new(name) + total = 0 -# it "returns an array of the words played by the player" do -# assert Player.plays.include?([]) -# end -# end - -# describe "Player#plays" do -# it "Does the 'plays' method exist" do -# Player.plays.wont_be_nil -# end -# end -# -# describe "Player#play(word)" do -# it "Does the play(word) method exist" do -# "Player#play(name).wont_be_nil" -# end -# end -# -# describe "Player#total_score" do -# it "Does the total_score method exist" do -# "Player#total_score.wont_be_nil" -# end -# end -# -# describe "Player#won?" do -# it "Does the won? method exist" do -# "Player#won?.wont_be_nil" -# end -# end -# -# describe "Player#highest_scoring_word" do -# it "Does the highest_scoring_word method exist" do -# "Player#highest_scoring_word.wont_be_nil" -# end -# end -# -# describe "Player#highest_word_score?" do -# it "Does the highest_word_score method exist" do -# "Player#highest_word_score.wont_be_nil" -# end -# end + it "Does it return the total score" do + TEST_CASES.each do |word| + total += total.total_score + total.must_equal(Scoring.score(word)) + end + end + end +end From 4f5f31612bbe42e0268b4ad1ad5b51c82eeb8a59 Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Fri, 11 Mar 2016 10:40:19 -0800 Subject: [PATCH 28/39] Got total_score working. --- lib/player.rb | 7 +++++-- spec/player-spec.rb | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 66137f8e..9d2dbded 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -10,7 +10,6 @@ def initialize(name) end def plays - @words return @words end @@ -21,6 +20,10 @@ def play(word) end def total_score - + tally = 0 + @words.each do |word| + tally += Scoring.score(word) + end + return tally end end diff --git a/spec/player-spec.rb b/spec/player-spec.rb index f60ed26c..ccb91e0b 100644 --- a/spec/player-spec.rb +++ b/spec/player-spec.rb @@ -53,9 +53,9 @@ it "Does it return the total score" do TEST_CASES.each do |word| - total += total.total_score - total.must_equal(Scoring.score(word)) + test_player.play(word) end + test_player.total_score.must_equal(25) end end end From 0a1518e5223a406977001ed2c64137909430fe32 Mon Sep 17 00:00:00 2001 From: Adriana Date: Fri, 11 Mar 2016 10:55:49 -0800 Subject: [PATCH 29/39] Added a test for won? method. Then made the won? method return true if WIN CONDITION is met. Added in an if statement in play(word) method to return false if the player has won. --- lib/player.rb | 14 ++++++++++++-- spec/player-spec.rb | 16 ++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 9d2dbded..80b44912 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -14,8 +14,11 @@ def plays end def play(word) - @word_score = Scoring.score(word) - @words << word + if self.won? == true + return false + end + @word_score = Scoring.score(word) + @words << word return @word_score end @@ -26,4 +29,11 @@ def total_score end return tally end + + def won? + if total_score > WIN_CONDITION + return true + end + return false + end end diff --git a/spec/player-spec.rb b/spec/player-spec.rb index ccb91e0b..8295671b 100644 --- a/spec/player-spec.rb +++ b/spec/player-spec.rb @@ -2,7 +2,8 @@ require_relative '../lib/player' TEST_CASES = ["word", "butt", "fart", "red"] - +WIN_CASE = ["cazique", "mezquit"] +WINNING = 100 describe Player do @@ -49,7 +50,6 @@ describe "#total_score" do test_player = Player.new(name) - total = 0 it "Does it return the total score" do TEST_CASES.each do |word| @@ -58,4 +58,16 @@ test_player.total_score.must_equal(25) end end + + describe "#won?" do + + test_player = Player.new(name) + + it "Does it return true if the player won?" do + WIN_CASE.each do |word| + test_player.play(word) + end + assert test_player.won? == true + end + end end From 7c244bbfad994987fe8e2fbee08e00d047f527be Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Fri, 11 Mar 2016 11:28:50 -0800 Subject: [PATCH 30/39] Started working on highest_scoring_word method. Doing our best to use max and max_by in a hash. Should be returning the highest scoring word, currently returning nil. Not sure why. We're not entirely comfortable in our understanding of hashes and enumerables. --- lib/player.rb | 25 +++++++++++++++++-------- spec/player-spec.rb | 12 ++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 80b44912..805d5add 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -3,10 +3,9 @@ class Player WIN_CONDITION = 100 def initialize(name) - @name = name - @words = [] - @word_score = 0 - + @name = name + @words = [] + @word_score = 0 end def plays @@ -17,17 +16,17 @@ def play(word) if self.won? == true return false end - @word_score = Scoring.score(word) - @words << word + @word_score = Scoring.score(word) + @words << word return @word_score end def total_score tally = 0 @words.each do |word| - tally += Scoring.score(word) + tally += Scoring.score(word) end - return tally + return tally end def won? @@ -36,4 +35,14 @@ def won? end return false end + + def highest_scoring_word + words_and_scores = Hash.new {|hash, key| hash[key] = []} + @words.each do |word| + words_and_scores[:word] << (Scoring.score(word)) + end + words_and_scores.max_by do |key, value| + return words_and_scores.key(value.max) + end + end end diff --git a/spec/player-spec.rb b/spec/player-spec.rb index 8295671b..11fa0202 100644 --- a/spec/player-spec.rb +++ b/spec/player-spec.rb @@ -70,4 +70,16 @@ assert test_player.won? == true end end + + describe "#highest_scoring_word" do + + test_player = Player.new(name) + + it "Does it return the highest scoring WORD" do + TEST_CASES.each do |word| + test_player.play(word) + end + test_player.highest_scoring_word.must_equal("word") + end + end end From 4f47d6cdc9373ab0184aa0028162e82a056e72dd Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Fri, 11 Mar 2016 13:15:22 -0800 Subject: [PATCH 31/39] Made highest_scoring_word method return highest scoring word by utilizing a hash and max_by. --- lib/player.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 805d5add..d9aeebdd 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -37,12 +37,14 @@ def won? end def highest_scoring_word - words_and_scores = Hash.new {|hash, key| hash[key] = []} + words_and_scores = { } + most = [] @words.each do |word| - words_and_scores[:word] << (Scoring.score(word)) - end - words_and_scores.max_by do |key, value| - return words_and_scores.key(value.max) + words_and_scores[word] = (Scoring.score(word)) end + most = words_and_scores.max_by do |key, value| + value + end + return most[0] end end From 6eb6d07135ee4cc61a3f7b51e47d5bec8143f6ce Mon Sep 17 00:00:00 2001 From: Adriana Date: Fri, 11 Mar 2016 13:26:45 -0800 Subject: [PATCH 32/39] Finished highest_score_word method and tests, finished highest_word_score method and tests. Shaved some yaks creating tilebag.rb and the accompanying spec for it --- lib/player.rb | 12 +++ lib/tilebag.rb | 0 scrabble.rb | 4 + spec/player-spec.rb | 187 ++++++++++++++++++++++++------------------- spec/tilebag-spec.rb | 2 + 5 files changed, 123 insertions(+), 82 deletions(-) create mode 100644 lib/tilebag.rb create mode 100644 spec/tilebag-spec.rb diff --git a/lib/player.rb b/lib/player.rb index d9aeebdd..accb69ea 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -47,4 +47,16 @@ def highest_scoring_word end return most[0] end + + def highest_word_score + words_and_scores = { } + most = [] + @words.each do |word| + words_and_scores[Scoring.score(word)] = word + end + most = words_and_scores.max_by do |key, value| + key + end + return most[0] + end end diff --git a/lib/tilebag.rb b/lib/tilebag.rb new file mode 100644 index 00000000..e69de29b diff --git a/scrabble.rb b/scrabble.rb index 5c888d9d..826ef672 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -1,5 +1,6 @@ require 'lib/scoring.rb' require 'lib/player.rb' +require 'lib/tilebag.rb' module Scrabble class Scoring @@ -7,4 +8,7 @@ class Scoring class Player end + + class TileBag + end end diff --git a/spec/player-spec.rb b/spec/player-spec.rb index 11fa0202..533b9c95 100644 --- a/spec/player-spec.rb +++ b/spec/player-spec.rb @@ -1,85 +1,108 @@ require_relative './spec_helper' require_relative '../lib/player' -TEST_CASES = ["word", "butt", "fart", "red"] -WIN_CASE = ["cazique", "mezquit"] -WINNING = 100 - - -describe Player do - it "Does the Player Class exist test?" do - Player.wont_be_nil - end - - describe "Player#new(name)" do - it "Does the class initialize with a name" do - Player.new(name).wont_be_nil - end - end - - describe "#plays" do - test_player = Player.new(name) - it "Does it contain an array" do - test_player.plays.must_be_kind_of Array - end - end - - describe "#play(word)" do - - test_player = Player.new(name) - - # TEST_CASES.each do |played_word| - it "Does it add the played word?" do - test_player.play("word") - test_player.plays.must_equal(["word"]) - end - # end - end - - describe "#play(word)" do - - test_player = Player.new(name) - - TEST_CASES.each do |played_word| - it "Does it return the score of the word" do - test_player.play(played_word).must_equal(Scoring.score(played_word)) - end - end - end - - describe "#total_score" do - - test_player = Player.new(name) - - it "Does it return the total score" do - TEST_CASES.each do |word| - test_player.play(word) - end - test_player.total_score.must_equal(25) - end - end - - describe "#won?" do - - test_player = Player.new(name) - - it "Does it return true if the player won?" do - WIN_CASE.each do |word| - test_player.play(word) - end - assert test_player.won? == true - end - end - - describe "#highest_scoring_word" do - - test_player = Player.new(name) - - it "Does it return the highest scoring WORD" do - TEST_CASES.each do |word| - test_player.play(word) - end - test_player.highest_scoring_word.must_equal("word") - end - end -end +# TEST_CASES = ["word", "butt", "fart", "red"] +# WIN_CASE = ["cazique", "mezquit"] +# WINNING = 100 +# +# +# describe Player do +# it "Does the Player Class exist test?" do +# Player.wont_be_nil +# end +# +# describe "Player#new(name)" do +# it "Does the class initialize with a name" do +# Player.new(name).wont_be_nil +# end +# end +# +# describe "#plays" do +# test_player = Player.new(name) +# it "Does it contain an array" do +# test_player.plays.must_be_kind_of Array +# end +# end +# +# describe "#play(word)" do +# +# test_player = Player.new(name) +# +# # TEST_CASES.each do |played_word| +# it "Does it add the played word?" do +# test_player.play("word") +# test_player.plays.must_equal(["word"]) +# end +# # end +# end +# +# describe "#play(word)" do +# +# test_player = Player.new(name) +# +# TEST_CASES.each do |played_word| +# it "Does it return the score of the word" do +# test_player.play(played_word).must_equal(Scoring.score(played_word)) +# end +# end +# end +# +# describe "#total_score" do +# +# test_player = Player.new(name) +# +# it "Does it return the total score" do +# TEST_CASES.each do |word| +# test_player.play(word) +# end +# test_player.total_score.must_equal(25) +# end +# end +# +# describe "#won?" do +# +# test_player = Player.new(name) +# +# it "Does it return true if the player won?" do +# WIN_CASE.each do |word| +# test_player.play(word) +# end +# assert test_player.won? == true +# end +# end +# +# describe "#highest_scoring_word" do +# +# test_player = Player.new(name) +# +# it "Does it return the highest scoring WORD" do +# TEST_CASES.each do |word| +# test_player.play(word) +# end +# test_player.highest_scoring_word.must_equal("word") +# end +# end +# +# describe "#highest_word_score" do +# +# test_player = Player.new(name) +# +# it "Does it return the highest word SCORE" do +# TEST_CASES.each do |word| +# test_player.play(word) +# end +# test_player.highest_word_score.must_equal(8) +# end +# end +# end +# +# +# +# +# +# +# +# +# +# +# # diff --git a/spec/tilebag-spec.rb b/spec/tilebag-spec.rb new file mode 100644 index 00000000..667f5ea0 --- /dev/null +++ b/spec/tilebag-spec.rb @@ -0,0 +1,2 @@ +require_relative './spec_helper' +require_relative '../lib/tilebag' From 23c08dba29f4ea47f8ac96d72b79a4f3ede4d8c3 Mon Sep 17 00:00:00 2001 From: Adriana Date: Fri, 11 Mar 2016 13:35:10 -0800 Subject: [PATCH 33/39] Added a test to see if the TileBag class exists. Made that test pass. Added the method draw_tiles --- lib/tilebag.rb | 21 +++++++++++++++++++++ spec/tilebag-spec.rb | 10 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index e69de29b..f273456e 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -0,0 +1,21 @@ +class TileBag + + def initialize + + @default_tiles = { + "A" => 9, "B" => 2, "C" => 2, + "D" => 4, "E" => 12, "F" => 2, + "G" => 3, "H" => 2, "I" => 9, + "J" => 1, "K" => 1, "L" => 4, + "M" => 2, "N" => 6, "O" => 8, + "P" => 2, "Q" => 1, "R" => 6, + "S" => 4, "T" => 6, "U" => 4, + "V" => 2, "W" => 2, "X" => 1, + "Y" => 2, "Z" => 1, + } + end + + def draw_tiles(num) + + end +end diff --git a/spec/tilebag-spec.rb b/spec/tilebag-spec.rb index 667f5ea0..d3af6147 100644 --- a/spec/tilebag-spec.rb +++ b/spec/tilebag-spec.rb @@ -1,2 +1,12 @@ require_relative './spec_helper' require_relative '../lib/tilebag' + + +describe TileBag do + it "Does the TileBag Class exist test?" do + TileBag.wont_be_nil + end + + + +end From 35f6e792b13d2fb41cb348fdbb483c99a53e4c23 Mon Sep 17 00:00:00 2001 From: Adriana Date: Fri, 11 Mar 2016 13:38:08 -0800 Subject: [PATCH 34/39] Added a test for number of tiles method --- spec/tilebag-spec.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/tilebag-spec.rb b/spec/tilebag-spec.rb index d3af6147..66f91c13 100644 --- a/spec/tilebag-spec.rb +++ b/spec/tilebag-spec.rb @@ -7,6 +7,12 @@ TileBag.wont_be_nil end - + describe "#draw_tiles" do + it "Does it return number of random tiles" do + test_tiles = TileBag.new + tile_list = test_tiles.draw_tiles(7) + tile_list.length.must_equal(7) + end + end end From af0759f552cd05cfb151bc3c688bdf361c1f6209 Mon Sep 17 00:00:00 2001 From: Adriana Date: Fri, 11 Mar 2016 14:54:35 -0800 Subject: [PATCH 35/39] Added a test for the draw_tiles(num) method. Added the method and got our test to pass --- lib/tilebag.rb | 9 +++++++++ spec/tilebag-spec.rb | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index f273456e..9b690930 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -16,6 +16,15 @@ def initialize end def draw_tiles(num) + your_tiles = [] + until your_tiles.length == num do + tiles_picked = @default_tiles.keys.sample + your_tiles << tiles_picked + end + #subtract tiles from @default_tiles + # sample = h.keys.sample example? + # h.select { |k,v| k == sample } + return your_tiles end end diff --git a/spec/tilebag-spec.rb b/spec/tilebag-spec.rb index 66f91c13..104b53ab 100644 --- a/spec/tilebag-spec.rb +++ b/spec/tilebag-spec.rb @@ -13,6 +13,19 @@ tile_list = test_tiles.draw_tiles(7) tile_list.length.must_equal(7) end - end + end + + # describe "#draw_tiles" do + # it "Does it return the correct amount of tiles left" do + # test_tiles = TileBag.new + # tile_list = test_tiles.draw_tiles(7) + # tile_list.draw_tiles.must_equal(91) + # end + # describe "#draw_tiles" do + # it "Does it the correct amount each tile" do + # test_tiles = TileBag.new + # tile_list = test_tiles.draw_tiles(7) + # tile_list.length.must_equal(7) + # end end From eafd864636f928300363391119f6566f52922e15 Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Fri, 11 Mar 2016 15:45:54 -0800 Subject: [PATCH 36/39] Got stalled out on how to test the second part of the draw_tiles(num) method, however, we are confident that the method works. Started work on tiles_remaining test. It should be good, once write the method. --- lib/tilebag.rb | 4 ++++ spec/tilebag-spec.rb | 35 ++++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index 9b690930..bbe5dc32 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -20,8 +20,12 @@ def draw_tiles(num) until your_tiles.length == num do tiles_picked = @default_tiles.keys.sample your_tiles << tiles_picked + value = @default_tiles[tiles_picked] + new_value = value - 1 + @default_tiles[tiles_picked] = new_value end + #subtract tiles from @default_tiles # sample = h.keys.sample example? # h.select { |k,v| k == sample } diff --git a/spec/tilebag-spec.rb b/spec/tilebag-spec.rb index 104b53ab..ed0e1764 100644 --- a/spec/tilebag-spec.rb +++ b/spec/tilebag-spec.rb @@ -15,17 +15,26 @@ end end - # describe "#draw_tiles" do - # it "Does it return the correct amount of tiles left" do - # test_tiles = TileBag.new - # tile_list = test_tiles.draw_tiles(7) - # tile_list.draw_tiles.must_equal(91) - # end - - # describe "#draw_tiles" do - # it "Does it the correct amount each tile" do - # test_tiles = TileBag.new - # tile_list = test_tiles.draw_tiles(7) - # tile_list.length.must_equal(7) - # end + describe "#tiles_remaining" do + it "Does it return the correct amount of tiles left" do + test_tiles = TileBag.new + tile_list = test_tiles.draw_tiles(7) + tile_list.draw_tiles.must_equal(98) + end + end + + + end + + + +#TRYING TO FIGURE OUT IF IT IS SUBTRACTING CORRECT TILES. CURRENTLY UNABLE TO MAKE IT WORK. WILL COME BACK. +# describe "#draw_tiles" do +# +# it "Does it subtract the correct tiles from tile chosen?" do +# test_tiles = TileBag.new +# test_tiles.draw_tiles(2).must_equal(3) +# +# end +# end From 18e3c664cd65bd971964e8d102e9a62f226f8a6d Mon Sep 17 00:00:00 2001 From: Adriana Date: Fri, 11 Mar 2016 16:04:58 -0800 Subject: [PATCH 37/39] Made a test for tiles_remaining, added it's corresponding method and made it pass --- lib/tilebag.rb | 10 ++++++++-- spec/tilebag-spec.rb | 7 +++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index bbe5dc32..cc137960 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -1,7 +1,6 @@ class TileBag - + attr_reader :total_tiles def initialize - @default_tiles = { "A" => 9, "B" => 2, "C" => 2, "D" => 4, "E" => 12, "F" => 2, @@ -13,6 +12,7 @@ def initialize "V" => 2, "W" => 2, "X" => 1, "Y" => 2, "Z" => 1, } + @total_tiles = 98 end def draw_tiles(num) @@ -31,4 +31,10 @@ def draw_tiles(num) # h.select { |k,v| k == sample } return your_tiles end + + def tiles_remaining + @total_tiles -= self.draw_tiles(num).length + return @total_tiles + end + end diff --git a/spec/tilebag-spec.rb b/spec/tilebag-spec.rb index ed0e1764..a258694e 100644 --- a/spec/tilebag-spec.rb +++ b/spec/tilebag-spec.rb @@ -16,15 +16,14 @@ end describe "#tiles_remaining" do - it "Does it return the correct amount of tiles left" do + it "Does it return tiles remaining" do test_tiles = TileBag.new - tile_list = test_tiles.draw_tiles(7) - tile_list.draw_tiles.must_equal(98) + test_tiles.tiles_remaining.must_equal(91) end end - + end From 6aab539afabd41032f5ed0e4366b982020a72d43 Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Fri, 11 Mar 2016 16:16:09 -0800 Subject: [PATCH 38/39] Uncommented out our passing tests that we had previously commented out, so that we had less to look at while raking. --- spec/player-spec.rb | 199 ++++++++++++++++++++----------------------- spec/scoring-spec.rb | 98 ++++++++++----------- spec/tilebag-spec.rb | 3 - 3 files changed, 143 insertions(+), 157 deletions(-) diff --git a/spec/player-spec.rb b/spec/player-spec.rb index 533b9c95..31e9442d 100644 --- a/spec/player-spec.rb +++ b/spec/player-spec.rb @@ -1,108 +1,97 @@ require_relative './spec_helper' require_relative '../lib/player' -# TEST_CASES = ["word", "butt", "fart", "red"] -# WIN_CASE = ["cazique", "mezquit"] -# WINNING = 100 -# -# -# describe Player do -# it "Does the Player Class exist test?" do -# Player.wont_be_nil -# end -# -# describe "Player#new(name)" do -# it "Does the class initialize with a name" do -# Player.new(name).wont_be_nil -# end -# end -# -# describe "#plays" do -# test_player = Player.new(name) -# it "Does it contain an array" do -# test_player.plays.must_be_kind_of Array -# end -# end -# -# describe "#play(word)" do -# -# test_player = Player.new(name) -# -# # TEST_CASES.each do |played_word| -# it "Does it add the played word?" do -# test_player.play("word") -# test_player.plays.must_equal(["word"]) -# end -# # end -# end -# -# describe "#play(word)" do -# -# test_player = Player.new(name) -# -# TEST_CASES.each do |played_word| -# it "Does it return the score of the word" do -# test_player.play(played_word).must_equal(Scoring.score(played_word)) -# end -# end -# end -# -# describe "#total_score" do -# -# test_player = Player.new(name) -# -# it "Does it return the total score" do -# TEST_CASES.each do |word| -# test_player.play(word) -# end -# test_player.total_score.must_equal(25) -# end -# end -# -# describe "#won?" do -# -# test_player = Player.new(name) -# -# it "Does it return true if the player won?" do -# WIN_CASE.each do |word| -# test_player.play(word) -# end -# assert test_player.won? == true -# end -# end -# -# describe "#highest_scoring_word" do -# -# test_player = Player.new(name) -# -# it "Does it return the highest scoring WORD" do -# TEST_CASES.each do |word| -# test_player.play(word) -# end -# test_player.highest_scoring_word.must_equal("word") -# end -# end -# -# describe "#highest_word_score" do -# -# test_player = Player.new(name) -# -# it "Does it return the highest word SCORE" do -# TEST_CASES.each do |word| -# test_player.play(word) -# end -# test_player.highest_word_score.must_equal(8) -# end -# end -# end -# -# -# -# -# -# -# -# -# -# -# # +TEST_CASES = ["word", "butt", "fart", "red"] +WIN_CASE = ["cazique", "mezquit"] +WINNING = 100 + + +describe Player do + it "Does the Player Class exist test?" do + Player.wont_be_nil + end + + describe "Player#new(name)" do + it "Does the class initialize with a name" do + Player.new(name).wont_be_nil + end + end + + describe "#plays" do + test_player = Player.new(name) + it "Does it contain an array" do + test_player.plays.must_be_kind_of Array + end + end + + describe "#play(word)" do + + test_player = Player.new(name) + + # TEST_CASES.each do |played_word| + it "Does it add the played word?" do + test_player.play("word") + test_player.plays.must_equal(["word"]) + end + # end + end + + describe "#play(word)" do + + test_player = Player.new(name) + + TEST_CASES.each do |played_word| + it "Does it return the score of the word" do + test_player.play(played_word).must_equal(Scoring.score(played_word)) + end + end + end + + describe "#total_score" do + + test_player = Player.new(name) + + it "Does it return the total score" do + TEST_CASES.each do |word| + test_player.play(word) + end + test_player.total_score.must_equal(25) + end + end + + describe "#won?" do + + test_player = Player.new(name) + + it "Does it return true if the player won?" do + WIN_CASE.each do |word| + test_player.play(word) + end + assert test_player.won? == true + end + end + + describe "#highest_scoring_word" do + + test_player = Player.new(name) + + it "Does it return the highest scoring WORD" do + TEST_CASES.each do |word| + test_player.play(word) + end + test_player.highest_scoring_word.must_equal("word") + end + end + + describe "#highest_word_score" do + + test_player = Player.new(name) + + it "Does it return the highest word SCORE" do + TEST_CASES.each do |word| + test_player.play(word) + end + test_player.highest_word_score.must_equal(8) + end + end +end diff --git a/spec/scoring-spec.rb b/spec/scoring-spec.rb index 1b47945a..504ddd1f 100644 --- a/spec/scoring-spec.rb +++ b/spec/scoring-spec.rb @@ -1,52 +1,52 @@ require_relative './spec_helper' require_relative '../lib/scoring' -# describe Scoring do -# it "Does the Scoring Class exist?" do -# Scoring.wont_be_nil -# end -# -# describe "Scoring#score(word)" do -# HASH_CASES = { -# "cat" => 5, -# "CAT" => 5, -# "BOX" => 12, -# "box" => 12, -# "googles" => 59, -# "GOOgles" => 59, -# "m" => 3, -# "f" => 4, -# "v" => 4, -# "k" => 5, -# "j" => 8, -# "z" => 10 -# } -# -# HASH_CASES.each do |letters, score| -# it "Does it assign a score number to each letter" do -# Scoring.score(letters).must_equal(score) -# end -# end -# end -# -# describe "Scoring#highest_score_from(array_of_words)" do -# ARRAY_CASES = { -# "cat" => ["cat"], -# "box" => ["cat", "box"], -# "box" => ["phone", "box", "cat"], -# "purple" => ["purple", "farts", "hands", "butts"], -# "hands" => ["hands", "violet"], -# "hands" => ["violet", "hands"], -# "jukebox" => ["jukebox", "cazique", "mezquit"], -# "mezquit" => ["mezquit", "jukebox", "cazique"], -# "buzzcut" => ["jukebox", "buzzcut"], -# "buzzcut" => ["buzzcut", "jukebox"] -# } -# -# ARRAY_CASES.each do |key, value| -# it "Does it return the highest score" do -# Scoring.highest_score_from(value).must_equal(key) -# end -# end -# end -# end +describe Scoring do + it "Does the Scoring Class exist?" do + Scoring.wont_be_nil + end + + describe "Scoring#score(word)" do + HASH_CASES = { + "cat" => 5, + "CAT" => 5, + "BOX" => 12, + "box" => 12, + "googles" => 59, + "GOOgles" => 59, + "m" => 3, + "f" => 4, + "v" => 4, + "k" => 5, + "j" => 8, + "z" => 10 + } + + HASH_CASES.each do |letters, score| + it "Does it assign a score number to each letter" do + Scoring.score(letters).must_equal(score) + end + end + end + + describe "Scoring#highest_score_from(array_of_words)" do + ARRAY_CASES = { + "cat" => ["cat"], + "box" => ["cat", "box"], + "box" => ["phone", "box", "cat"], + "purple" => ["purple", "farts", "hands", "butts"], + "hands" => ["hands", "violet"], + "hands" => ["violet", "hands"], + "jukebox" => ["jukebox", "cazique", "mezquit"], + "mezquit" => ["mezquit", "jukebox", "cazique"], + "buzzcut" => ["jukebox", "buzzcut"], + "buzzcut" => ["buzzcut", "jukebox"] + } + + ARRAY_CASES.each do |key, value| + it "Does it return the highest score" do + Scoring.highest_score_from(value).must_equal(key) + end + end + end +end diff --git a/spec/tilebag-spec.rb b/spec/tilebag-spec.rb index a258694e..d5dedc94 100644 --- a/spec/tilebag-spec.rb +++ b/spec/tilebag-spec.rb @@ -21,9 +21,6 @@ test_tiles.tiles_remaining.must_equal(91) end end - - - end From 227b781094b70c945dd4037952a123ffde2f8172 Mon Sep 17 00:00:00 2001 From: Jillian Boshart Date: Thu, 7 Apr 2016 14:33:24 -0700 Subject: [PATCH 39/39] In working on ScrabbleSinatra I found that I wanted a method to check if the words being scored contained any character that was not a letter, so I wrote it. I checked with Adriana to make sure it was cool with her if I pushed this to our repo, and she said it was. Thanks, Adriana! --- lib/scoring.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/scoring.rb b/lib/scoring.rb index 0f0f10f4..d999b1b9 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -9,6 +9,10 @@ class Scoring "q" => 10, "z" => 10 } + def self.check_if_letters(word) + !word.match(/[^A-Za-z]/) + end + def self.score(word) arr = word.downcase.split(//) arr.length == 7 ? tally = 50 : tally = 0