From 0aae26ab83b08a2f6572513a5c31032cec9b0619 Mon Sep 17 00:00:00 2001 From: seanreed1111 Date: Sun, 28 Aug 2016 15:28:43 -0400 Subject: [PATCH 01/13] [WIP] add dominoes From 38175f3a86f709400b5c2dc5b61a37804c545629 Mon Sep 17 00:00:00 2001 From: seanreed1111 Date: Sun, 28 Aug 2016 17:06:00 -0400 Subject: [PATCH 02/13] begins setting up tests. --- bin/generate-dominoes | 7 ++ exercises/dominoes/.version | 1 + exercises/dominoes/dominoes_test.rb | 114 ++++++++++++++++++++++++++++ exercises/dominoes/example.rb | 14 ++++ exercises/dominoes/example.tt | 21 +++++ lib/dominoes_cases.rb | 11 +++ 6 files changed, 168 insertions(+) create mode 100755 bin/generate-dominoes create mode 100644 exercises/dominoes/.version create mode 100644 exercises/dominoes/dominoes_test.rb create mode 100644 exercises/dominoes/example.rb create mode 100644 exercises/dominoes/example.tt create mode 100644 lib/dominoes_cases.rb diff --git a/bin/generate-dominoes b/bin/generate-dominoes new file mode 100755 index 0000000000..90b3f645c0 --- /dev/null +++ b/bin/generate-dominoes @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby + +require_relative '../lib/helper' +require 'generator' +require 'dominoes_cases' + +Generator.new('dominoes', DominoesCases).generate \ No newline at end of file diff --git a/exercises/dominoes/.version b/exercises/dominoes/.version new file mode 100644 index 0000000000..d8263ee986 --- /dev/null +++ b/exercises/dominoes/.version @@ -0,0 +1 @@ +2 \ No newline at end of file diff --git a/exercises/dominoes/dominoes_test.rb b/exercises/dominoes/dominoes_test.rb new file mode 100644 index 0000000000..e27575e0ba --- /dev/null +++ b/exercises/dominoes/dominoes_test.rb @@ -0,0 +1,114 @@ +#!/usr/bin/env ruby +gem 'minitest', '>= 5.0.0' +require 'minitest/autorun' +require_relative 'dominoes' + +# Test data version: +# 08a0cda +class DominoesTest < Minitest::Test + def test_empty_input + skip + expect = true + actual = Dominoes.new.can_chain?([]) + assert_equal(expect, actual) + end + + def test_singleton_input_chainable + skip + expect = true + actual = Dominoes.new.can_chain?([[1, 1]]) + assert_equal(expect, actual) + end + + def test_singleton_input_not_chainable + skip + expect = false + actual = Dominoes.new.can_chain?([[1, 2]]) + assert_equal(expect, actual) + end + + def test_three_elements + skip + expect = true + actual = Dominoes.new.can_chain?([[1, 2], [3, 1], [2, 3]]) + assert_equal(expect, actual) + end + + def test_can_reverse_dominoes + skip + expect = true + actual = Dominoes.new.can_chain?([[1, 2], [1, 3], [2, 3]]) + assert_equal(expect, actual) + end + + def test_cant_be_chained + skip + expect = false + actual = Dominoes.new.can_chain?([[1, 2], [4, 1], [2, 3]]) + assert_equal(expect, actual) + end + + def disconnected_simple + skip + expect = false + actual = Dominoes.new.can_chain?([[1, 1], [2, 2]]) + assert_equal(expect, actual) + end + + def disconnected_double_loop + skip + expect = false + actual = Dominoes.new.can_chain?([[1, 2], [2, 1], [3, 4], [4, 3]]) + assert_equal(expect, actual) + end + + def disconnected_single_isolated + skip + expect = false + actual = Dominoes.new.can_chain?([[1, 2], [2, 1], [3, 4], [4, 3]]) + assert_equal(expect, actual) + end + + def need_backtrack + skip + expect = true + actual = Dominoes.new.can_chain?([[1, 2], [2, 1], [3, 4], [4, 3]]) + assert_equal(expect, actual) + end + + def + + expect = + actual = + assert_equal(expect, actual) + end + + def + + expect = + actual = + assert_equal(expect, actual) + end + + # Problems in exercism evolve over time, as we find better ways to ask + # questions. + # The version number refers to the version of the problem you solved, + # not your solution. + # + # Define a constant named VERSION inside of the top level BookKeeping + # module, which may be placed near the end of your file. + # + # In your file, it will look like this: + # + # module BookKeeping + # VERSION = 1 # Where the version number matches the one in the test. + # end + # + # If you are curious, read more about constants on RubyDoc: + # http://ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/constants.html + + def test_bookkeeping + skip + assert_equal 2, BookKeeping::VERSION + end +end diff --git a/exercises/dominoes/example.rb b/exercises/dominoes/example.rb new file mode 100644 index 0000000000..e89541b8eb --- /dev/null +++ b/exercises/dominoes/example.rb @@ -0,0 +1,14 @@ +module BookKeeping + VERSION = 2 +end + +class Dominoes + + def can_chain?(dominoes_list = []) + false + end + + def solve(dominoes_list = []) + + end +end \ No newline at end of file diff --git a/exercises/dominoes/example.tt b/exercises/dominoes/example.tt new file mode 100644 index 0000000000..a19cfc6af9 --- /dev/null +++ b/exercises/dominoes/example.tt @@ -0,0 +1,21 @@ +#!/usr/bin/env ruby +gem 'minitest', '>= 5.0.0' +require 'minitest/autorun' +require_relative 'dominoes' + +# Test data version: +# <%= sha1 %> +class DominoesTest < Minitest::Test<% test_cases.each do |test_case| %> + def <%= test_case.test_name %> + <%= test_case.skipped %> + expect = <%= test_case.expect %> + actual = <%= test_case.work_load %> + assert_equal(expect, actual) + end +<% end %> +<%= IO.read(XRUBY_LIB + '/bookkeeping.md') %> + def test_bookkeeping + skip + assert_equal <%= version.next %>, BookKeeping::VERSION + end +end diff --git a/lib/dominoes_cases.rb b/lib/dominoes_cases.rb new file mode 100644 index 0000000000..389ce7350b --- /dev/null +++ b/lib/dominoes_cases.rb @@ -0,0 +1,11 @@ +class DominoesCase < OpenStruct + + +end + +DominoesCases = proc do |data| + JSON.parse(data)['cases'].map.with_index do |row, i| + row = row.merge('index' => i) + DominoesCase.new(row) + end +end \ No newline at end of file From 8081c48b5f643fa9f27c372ffda35ee9fd8c25ee Mon Sep 17 00:00:00 2001 From: seanreed1111 Date: Sun, 28 Aug 2016 17:33:55 -0400 Subject: [PATCH 03/13] adds all tests --- exercises/dominoes/dominoes_test.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/exercises/dominoes/dominoes_test.rb b/exercises/dominoes/dominoes_test.rb index e27575e0ba..5ddfbd7805 100644 --- a/exercises/dominoes/dominoes_test.rb +++ b/exercises/dominoes/dominoes_test.rb @@ -48,45 +48,45 @@ def test_cant_be_chained assert_equal(expect, actual) end - def disconnected_simple + def test_disconnected_simple skip expect = false actual = Dominoes.new.can_chain?([[1, 1], [2, 2]]) assert_equal(expect, actual) end - def disconnected_double_loop + def test_disconnected_double_loop skip expect = false actual = Dominoes.new.can_chain?([[1, 2], [2, 1], [3, 4], [4, 3]]) assert_equal(expect, actual) end - def disconnected_single_isolated + def test_disconnected_single_isolated skip expect = false - actual = Dominoes.new.can_chain?([[1, 2], [2, 1], [3, 4], [4, 3]]) + actual = Dominoes.new.can_chain?([[1, 2], [2, 3], [3, 1], [4, 4]]) assert_equal(expect, actual) end - def need_backtrack + def test_need_backtrack skip expect = true - actual = Dominoes.new.can_chain?([[1, 2], [2, 1], [3, 4], [4, 3]]) + actual = Dominoes.new.can_chain?([[1, 2], [2, 3], [3, 1], [2, 4], [2, 4]]) assert_equal(expect, actual) end - def + def test_separate_loops - expect = - actual = + expect = true + actual = Dominoes.new.can_chain?([[1, 2], [2, 3], [3, 1], [1, 1], [2, 2], [3, 3]]) assert_equal(expect, actual) end - def + def test_ten_elements - expect = - actual = + expect = true + actual = Dominoes.new.can_chain?([[1, 2], [5, 3], [3, 1], [1, 2], [2, 4], [1, 6], [2, 3], [3, 4], [5, 6]]) assert_equal(expect, actual) end From 647b021735b54731d9db3450d6aea8af989e6029 Mon Sep 17 00:00:00 2001 From: seanreed1111 Date: Sun, 28 Aug 2016 17:53:51 -0400 Subject: [PATCH 04/13] first test passes --- exercises/dominoes/dominoes.rb | 8 ++++++ exercises/dominoes/dominoes_test.rb | 41 ++++++++++------------------- 2 files changed, 22 insertions(+), 27 deletions(-) create mode 100644 exercises/dominoes/dominoes.rb diff --git a/exercises/dominoes/dominoes.rb b/exercises/dominoes/dominoes.rb new file mode 100644 index 0000000000..9ea41187c5 --- /dev/null +++ b/exercises/dominoes/dominoes.rb @@ -0,0 +1,8 @@ +class Dominoes + + def can_chain?(dominoes_list = []) + result = false + return true if dominoes_list.length == 0 + result + end +end \ No newline at end of file diff --git a/exercises/dominoes/dominoes_test.rb b/exercises/dominoes/dominoes_test.rb index 5ddfbd7805..800eaf1515 100644 --- a/exercises/dominoes/dominoes_test.rb +++ b/exercises/dominoes/dominoes_test.rb @@ -7,87 +7,74 @@ # 08a0cda class DominoesTest < Minitest::Test def test_empty_input - skip - expect = true actual = Dominoes.new.can_chain?([]) - assert_equal(expect, actual) + assert(actual) end def test_singleton_input_chainable skip - expect = true actual = Dominoes.new.can_chain?([[1, 1]]) - assert_equal(expect, actual) + assert(actual) end def test_singleton_input_not_chainable skip - expect = false actual = Dominoes.new.can_chain?([[1, 2]]) - assert_equal(expect, actual) + refute(actual) end def test_three_elements skip - expect = true actual = Dominoes.new.can_chain?([[1, 2], [3, 1], [2, 3]]) - assert_equal(expect, actual) + assert(actual) end def test_can_reverse_dominoes skip - expect = true actual = Dominoes.new.can_chain?([[1, 2], [1, 3], [2, 3]]) - assert_equal(expect, actual) + assert(actual) end def test_cant_be_chained skip - expect = false actual = Dominoes.new.can_chain?([[1, 2], [4, 1], [2, 3]]) - assert_equal(expect, actual) + refute(actual) end def test_disconnected_simple skip - expect = false actual = Dominoes.new.can_chain?([[1, 1], [2, 2]]) - assert_equal(expect, actual) + refute(actual) end def test_disconnected_double_loop skip - expect = false actual = Dominoes.new.can_chain?([[1, 2], [2, 1], [3, 4], [4, 3]]) - assert_equal(expect, actual) + refute(actual) end def test_disconnected_single_isolated skip - expect = false actual = Dominoes.new.can_chain?([[1, 2], [2, 3], [3, 1], [4, 4]]) - assert_equal(expect, actual) + refute(actual) end def test_need_backtrack skip - expect = true actual = Dominoes.new.can_chain?([[1, 2], [2, 3], [3, 1], [2, 4], [2, 4]]) - assert_equal(expect, actual) + assert(actual) end def test_separate_loops - - expect = true + skip actual = Dominoes.new.can_chain?([[1, 2], [2, 3], [3, 1], [1, 1], [2, 2], [3, 3]]) - assert_equal(expect, actual) + assert(actual) end def test_ten_elements - - expect = true + skip actual = Dominoes.new.can_chain?([[1, 2], [5, 3], [3, 1], [1, 2], [2, 4], [1, 6], [2, 3], [3, 4], [5, 6]]) - assert_equal(expect, actual) + assert(actual) end # Problems in exercism evolve over time, as we find better ways to ask From 5e1731026f9bb42fd10a435011780886d70142f6 Mon Sep 17 00:00:00 2001 From: seanreed1111 Date: Sun, 28 Aug 2016 18:12:45 -0400 Subject: [PATCH 05/13] three tests passing --- exercises/dominoes/dominoes.rb | 14 ++++++++++++-- exercises/dominoes/dominoes_test.rb | 2 -- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/exercises/dominoes/dominoes.rb b/exercises/dominoes/dominoes.rb index 9ea41187c5..dfc2c6af78 100644 --- a/exercises/dominoes/dominoes.rb +++ b/exercises/dominoes/dominoes.rb @@ -1,8 +1,18 @@ class Dominoes - def can_chain?(dominoes_list = []) + # ([[x,y], [a,b], ...]) => Bool + def can_chain?(dominoes_list) result = false - return true if dominoes_list.length == 0 + + return true if dominoes_list.length == 0 # empty list + + if ((dominoes_list.length == 1) && (dominoes_list[0][0] == dominoes_list[0][1])) #singletons + return true + else + return false + end + + result end end \ No newline at end of file diff --git a/exercises/dominoes/dominoes_test.rb b/exercises/dominoes/dominoes_test.rb index 800eaf1515..0f68e25624 100644 --- a/exercises/dominoes/dominoes_test.rb +++ b/exercises/dominoes/dominoes_test.rb @@ -12,13 +12,11 @@ def test_empty_input end def test_singleton_input_chainable - skip actual = Dominoes.new.can_chain?([[1, 1]]) assert(actual) end def test_singleton_input_not_chainable - skip actual = Dominoes.new.can_chain?([[1, 2]]) refute(actual) end From 5470ce02795081bde4fdeebf4ca7bfde42e0f2dd Mon Sep 17 00:00:00 2001 From: seanreed1111 Date: Sun, 28 Aug 2016 18:20:02 -0400 Subject: [PATCH 06/13] renamed the faiing tests using suffix expect_fail --- exercises/dominoes/dominoes_test.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/exercises/dominoes/dominoes_test.rb b/exercises/dominoes/dominoes_test.rb index 0f68e25624..f3638232bf 100644 --- a/exercises/dominoes/dominoes_test.rb +++ b/exercises/dominoes/dominoes_test.rb @@ -16,13 +16,12 @@ def test_singleton_input_chainable assert(actual) end - def test_singleton_input_not_chainable + def test_singleton_input_not_chainable_expect_fail actual = Dominoes.new.can_chain?([[1, 2]]) refute(actual) end def test_three_elements - skip actual = Dominoes.new.can_chain?([[1, 2], [3, 1], [2, 3]]) assert(actual) end @@ -33,25 +32,25 @@ def test_can_reverse_dominoes assert(actual) end - def test_cant_be_chained + def test_cant_be_chained_expect_fail skip actual = Dominoes.new.can_chain?([[1, 2], [4, 1], [2, 3]]) refute(actual) end - def test_disconnected_simple + def test_disconnected_simple_expect_fail skip actual = Dominoes.new.can_chain?([[1, 1], [2, 2]]) refute(actual) end - def test_disconnected_double_loop + def test_disconnected_double_loop_expect_fail skip actual = Dominoes.new.can_chain?([[1, 2], [2, 1], [3, 4], [4, 3]]) refute(actual) end - def test_disconnected_single_isolated + def test_disconnected_single_isolated_expect_fail skip actual = Dominoes.new.can_chain?([[1, 2], [2, 3], [3, 1], [4, 4]]) refute(actual) From 070a66d47c10b8fb573c24369d71d81c352e04e9 Mon Sep 17 00:00:00 2001 From: seanreed1111 Date: Sun, 28 Aug 2016 19:24:59 -0400 Subject: [PATCH 07/13] makes sure all tests not yet implemented will fail --- exercises/dominoes/dominoes.rb | 7 ++++--- exercises/dominoes/dominoes_test.rb | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/exercises/dominoes/dominoes.rb b/exercises/dominoes/dominoes.rb index dfc2c6af78..ed86d204fb 100644 --- a/exercises/dominoes/dominoes.rb +++ b/exercises/dominoes/dominoes.rb @@ -1,18 +1,19 @@ class Dominoes - # ([[x,y], [a,b], ...]) => Bool + # [[x,y],[a,b], ...] => Bool def can_chain?(dominoes_list) result = false - + + # Base case : empty list return true if dominoes_list.length == 0 # empty list + #Base case : one domino if ((dominoes_list.length == 1) && (dominoes_list[0][0] == dominoes_list[0][1])) #singletons return true else return false end - result end end \ No newline at end of file diff --git a/exercises/dominoes/dominoes_test.rb b/exercises/dominoes/dominoes_test.rb index f3638232bf..06dd8d4b38 100644 --- a/exercises/dominoes/dominoes_test.rb +++ b/exercises/dominoes/dominoes_test.rb @@ -18,7 +18,7 @@ def test_singleton_input_chainable def test_singleton_input_not_chainable_expect_fail actual = Dominoes.new.can_chain?([[1, 2]]) - refute(actual) + assert(actual) end def test_three_elements @@ -35,25 +35,25 @@ def test_can_reverse_dominoes def test_cant_be_chained_expect_fail skip actual = Dominoes.new.can_chain?([[1, 2], [4, 1], [2, 3]]) - refute(actual) + assert(actual) end def test_disconnected_simple_expect_fail skip actual = Dominoes.new.can_chain?([[1, 1], [2, 2]]) - refute(actual) + assert(actual) end def test_disconnected_double_loop_expect_fail skip actual = Dominoes.new.can_chain?([[1, 2], [2, 1], [3, 4], [4, 3]]) - refute(actual) + assert(actual) end def test_disconnected_single_isolated_expect_fail skip actual = Dominoes.new.can_chain?([[1, 2], [2, 3], [3, 1], [4, 4]]) - refute(actual) + assert(actual) end def test_need_backtrack From bf2da69e36f1cc67c80a3b26a00925f781dc7787 Mon Sep 17 00:00:00 2001 From: seanreed1111 Date: Mon, 29 Aug 2016 18:15:07 -0400 Subject: [PATCH 08/13] restructures branch. does not work --- exercises/dominoes/dominoes.rb | 35 ++++++++++++++++++++++------- exercises/dominoes/dominoes_test.rb | 22 ++++++++++-------- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/exercises/dominoes/dominoes.rb b/exercises/dominoes/dominoes.rb index ed86d204fb..36da81279e 100644 --- a/exercises/dominoes/dominoes.rb +++ b/exercises/dominoes/dominoes.rb @@ -1,19 +1,38 @@ class Dominoes - # [[x,y],[a,b], ...] => Bool - def can_chain?(dominoes_list) + attr_reader :list + + def initialize(array) + if(array.present?) + array.each do |domino| + @list << Domino.new(domino[0], domino[1]) + end + else + @list = nil + end + + end + + # [Domino] => Bool + def can_chain? result = false # Base case : empty list - return true if dominoes_list.length == 0 # empty list + return @list.length.zero?# empty list #Base case : one domino - if ((dominoes_list.length == 1) && (dominoes_list[0][0] == dominoes_list[0][1])) #singletons - return true - else - return false - end + result = @list.length == 1 #singletons result end +end + +class Domino + attr_accessor :normal + attr_reader :reverse + + def initialize(left, right) + @normal = [left, right] + @reverse = [right, left] + end end \ No newline at end of file diff --git a/exercises/dominoes/dominoes_test.rb b/exercises/dominoes/dominoes_test.rb index 06dd8d4b38..54135e22d5 100644 --- a/exercises/dominoes/dominoes_test.rb +++ b/exercises/dominoes/dominoes_test.rb @@ -1,27 +1,31 @@ #!/usr/bin/env ruby gem 'minitest', '>= 5.0.0' require 'minitest/autorun' -require_relative 'dominoes' +require_relative './dominoes' # Test data version: # 08a0cda class DominoesTest < Minitest::Test def test_empty_input - actual = Dominoes.new.can_chain?([]) + dominoes = Dominoes.new([nil]) + actual = dominoes.can_chain?(nil) assert(actual) end def test_singleton_input_chainable - actual = Dominoes.new.can_chain?([[1, 1]]) + + actual = Dominoes.new.can_chain?([[1,1]]) assert(actual) end - def test_singleton_input_not_chainable_expect_fail + def test_singleton_input_not_chainable_expect_false + skip actual = Dominoes.new.can_chain?([[1, 2]]) assert(actual) end def test_three_elements + skip actual = Dominoes.new.can_chain?([[1, 2], [3, 1], [2, 3]]) assert(actual) end @@ -32,25 +36,25 @@ def test_can_reverse_dominoes assert(actual) end - def test_cant_be_chained_expect_fail + def test_cant_be_chained_expect_false skip actual = Dominoes.new.can_chain?([[1, 2], [4, 1], [2, 3]]) assert(actual) end - def test_disconnected_simple_expect_fail + def test_disconnected_simple_expect_false skip actual = Dominoes.new.can_chain?([[1, 1], [2, 2]]) assert(actual) end - def test_disconnected_double_loop_expect_fail + def test_disconnected_double_loop_expect_false skip actual = Dominoes.new.can_chain?([[1, 2], [2, 1], [3, 4], [4, 3]]) assert(actual) end - def test_disconnected_single_isolated_expect_fail + def test_disconnected_single_isolated_expect_false skip actual = Dominoes.new.can_chain?([[1, 2], [2, 3], [3, 1], [4, 4]]) assert(actual) @@ -93,6 +97,6 @@ def test_ten_elements def test_bookkeeping skip - assert_equal 2, BookKeeping::VERSION + assert_equal 1, BookKeeping::VERSION end end From d0d9fb46b7973a743f6443f4ab6e753e66ff9761 Mon Sep 17 00:00:00 2001 From: seanreed1111 Date: Wed, 31 Aug 2016 10:34:49 -0400 Subject: [PATCH 09/13] Revert "renamed the faiing tests using suffix expect_fail" went back to before I left thoughtbot This reverts commit 5470ce02795081bde4fdeebf4ca7bfde42e0f2dd. --- exercises/dominoes/dominoes.rb | 36 +++++++---------------------- exercises/dominoes/dominoes_test.rb | 31 +++++++++++-------------- 2 files changed, 22 insertions(+), 45 deletions(-) diff --git a/exercises/dominoes/dominoes.rb b/exercises/dominoes/dominoes.rb index 36da81279e..dfc2c6af78 100644 --- a/exercises/dominoes/dominoes.rb +++ b/exercises/dominoes/dominoes.rb @@ -1,38 +1,18 @@ class Dominoes - attr_reader :list + # ([[x,y], [a,b], ...]) => Bool + def can_chain?(dominoes_list) + result = false + + return true if dominoes_list.length == 0 # empty list - def initialize(array) - if(array.present?) - array.each do |domino| - @list << Domino.new(domino[0], domino[1]) - end + if ((dominoes_list.length == 1) && (dominoes_list[0][0] == dominoes_list[0][1])) #singletons + return true else - @list = nil + return false end - end - - # [Domino] => Bool - def can_chain? - result = false - - # Base case : empty list - return @list.length.zero?# empty list - - #Base case : one domino - result = @list.length == 1 #singletons result end -end - -class Domino - attr_accessor :normal - attr_reader :reverse - - def initialize(left, right) - @normal = [left, right] - @reverse = [right, left] - end end \ No newline at end of file diff --git a/exercises/dominoes/dominoes_test.rb b/exercises/dominoes/dominoes_test.rb index 54135e22d5..0f68e25624 100644 --- a/exercises/dominoes/dominoes_test.rb +++ b/exercises/dominoes/dominoes_test.rb @@ -1,27 +1,24 @@ #!/usr/bin/env ruby gem 'minitest', '>= 5.0.0' require 'minitest/autorun' -require_relative './dominoes' +require_relative 'dominoes' # Test data version: # 08a0cda class DominoesTest < Minitest::Test def test_empty_input - dominoes = Dominoes.new([nil]) - actual = dominoes.can_chain?(nil) + actual = Dominoes.new.can_chain?([]) assert(actual) end def test_singleton_input_chainable - - actual = Dominoes.new.can_chain?([[1,1]]) + actual = Dominoes.new.can_chain?([[1, 1]]) assert(actual) end - def test_singleton_input_not_chainable_expect_false - skip + def test_singleton_input_not_chainable actual = Dominoes.new.can_chain?([[1, 2]]) - assert(actual) + refute(actual) end def test_three_elements @@ -36,28 +33,28 @@ def test_can_reverse_dominoes assert(actual) end - def test_cant_be_chained_expect_false + def test_cant_be_chained skip actual = Dominoes.new.can_chain?([[1, 2], [4, 1], [2, 3]]) - assert(actual) + refute(actual) end - def test_disconnected_simple_expect_false + def test_disconnected_simple skip actual = Dominoes.new.can_chain?([[1, 1], [2, 2]]) - assert(actual) + refute(actual) end - def test_disconnected_double_loop_expect_false + def test_disconnected_double_loop skip actual = Dominoes.new.can_chain?([[1, 2], [2, 1], [3, 4], [4, 3]]) - assert(actual) + refute(actual) end - def test_disconnected_single_isolated_expect_false + def test_disconnected_single_isolated skip actual = Dominoes.new.can_chain?([[1, 2], [2, 3], [3, 1], [4, 4]]) - assert(actual) + refute(actual) end def test_need_backtrack @@ -97,6 +94,6 @@ def test_ten_elements def test_bookkeeping skip - assert_equal 1, BookKeeping::VERSION + assert_equal 2, BookKeeping::VERSION end end From 50278bca04ebdd7afcfa6a6ac7c7999c664da7c1 Mon Sep 17 00:00:00 2001 From: seanreed1111 Date: Wed, 31 Aug 2016 10:41:46 -0400 Subject: [PATCH 10/13] refactors can_chain? using Tute's suggestions --- exercises/dominoes/dominoes.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/exercises/dominoes/dominoes.rb b/exercises/dominoes/dominoes.rb index dfc2c6af78..cf38276637 100644 --- a/exercises/dominoes/dominoes.rb +++ b/exercises/dominoes/dominoes.rb @@ -4,14 +4,8 @@ class Dominoes def can_chain?(dominoes_list) result = false - return true if dominoes_list.length == 0 # empty list - - if ((dominoes_list.length == 1) && (dominoes_list[0][0] == dominoes_list[0][1])) #singletons - return true - else - return false - end - + return true if dominoes_list.length.zero? # empty list + return (dominoes_list[0][0] == dominoes_list[0][1]) if dominoes_list.length == 1 #singletons result end From 90b8e4f3d4effb2a86eddc070af2cc5029dc1bf9 Mon Sep 17 00:00:00 2001 From: seanreed1111 Date: Thu, 1 Sep 2016 09:47:18 -0400 Subject: [PATCH 11/13] adds Domino class --- exercises/dominoes/domino.rb | 12 ++++++++++++ exercises/dominoes/dominoes.rb | 14 +++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 exercises/dominoes/domino.rb diff --git a/exercises/dominoes/domino.rb b/exercises/dominoes/domino.rb new file mode 100644 index 0000000000..e8bfb96d4c --- /dev/null +++ b/exercises/dominoes/domino.rb @@ -0,0 +1,12 @@ +class Domino + attr_reader :left, :right + + def initialize(left, right) + @left = left + @right = right + end + + def double? + left == right + end +end \ No newline at end of file diff --git a/exercises/dominoes/dominoes.rb b/exercises/dominoes/dominoes.rb index cf38276637..1d5f4ce080 100644 --- a/exercises/dominoes/dominoes.rb +++ b/exercises/dominoes/dominoes.rb @@ -1,12 +1,20 @@ class Dominoes + require_relative 'domino' + + def make_dominoes(list) + end + + # ([[x,y], [a,b], ...]) => Bool - def can_chain?(dominoes_list) + def can_chain?(list) result = false - return true if dominoes_list.length.zero? # empty list - return (dominoes_list[0][0] == dominoes_list[0][1]) if dominoes_list.length == 1 #singletons + return true if list.length.zero? # empty list + return (list[0][0] == list[0][1]) if list.length == 1 #singletons result end + + end \ No newline at end of file From 795051e633f360fd953bd81825cb6af64810261a Mon Sep 17 00:00:00 2001 From: seanreed1111 Date: Thu, 1 Sep 2016 10:36:13 -0400 Subject: [PATCH 12/13] refactors dominoes class --- exercises/dominoes/dominoes.rb | 41 +++++++++++++++++++++++++---- exercises/dominoes/dominoes_test.rb | 6 ++--- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/exercises/dominoes/dominoes.rb b/exercises/dominoes/dominoes.rb index 1d5f4ce080..f76c8f1964 100644 --- a/exercises/dominoes/dominoes.rb +++ b/exercises/dominoes/dominoes.rb @@ -1,20 +1,51 @@ class Dominoes require_relative 'domino' + attr_accessor :list - def make_dominoes(list) + #[ArrayTuples] => [Domino] + def initialize(arr_form_of_dominoes =[]) + @list = [] + if !arr_form_of_dominoes.empty? + arr_form_of_dominoes.each do |item| + @list << Domino.new(item[0], item[1]) + end + end end - - # ([[x,y], [a,b], ...]) => Bool - def can_chain?(list) + # [Domino] => Bool + def can_chain? result = false return true if list.length.zero? # empty list - return (list[0][0] == list[0][1]) if list.length == 1 #singletons + return (list.first.double?) if list.length == 1 #singletons result end + def first + @list[0] + end + + # # [ArrayTuples] => Bool + # def can_chain_list?(arr_form_of_dominoes) + # result = false + + # return true if arr_list.length.zero? # empty list + # return (arr_list[0][0] == arr_list[0][1]) if arr_list.length == 1 #singletons + + # result + # end + + + # def self.make_dominoes!(arr_form_of_dominoes =[]) + # @list = [] + # if !arr_form_of_dominoes.empty? + # arr_form_of_dominoes.each do |item| + # @list << Domino.new(item[0], item[1]) + # end + # end + # end + end \ No newline at end of file diff --git a/exercises/dominoes/dominoes_test.rb b/exercises/dominoes/dominoes_test.rb index 0f68e25624..e67a6838d6 100644 --- a/exercises/dominoes/dominoes_test.rb +++ b/exercises/dominoes/dominoes_test.rb @@ -7,17 +7,17 @@ # 08a0cda class DominoesTest < Minitest::Test def test_empty_input - actual = Dominoes.new.can_chain?([]) + actual = Dominoes.new([]).can_chain? assert(actual) end def test_singleton_input_chainable - actual = Dominoes.new.can_chain?([[1, 1]]) + actual = Dominoes.new([[1, 1]]).can_chain? assert(actual) end def test_singleton_input_not_chainable - actual = Dominoes.new.can_chain?([[1, 2]]) + actual = Dominoes.new([[1, 2]]).can_chain? refute(actual) end From 16853cdb6243baad432201a9a576b6f5eb533985 Mon Sep 17 00:00:00 2001 From: seanreed1111 Date: Thu, 1 Sep 2016 11:22:59 -0400 Subject: [PATCH 13/13] adds deep_copy to domino and dominoes classes --- exercises/dominoes/domino.rb | 4 ++++ exercises/dominoes/dominoes.rb | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/exercises/dominoes/domino.rb b/exercises/dominoes/domino.rb index e8bfb96d4c..45926dcc7b 100644 --- a/exercises/dominoes/domino.rb +++ b/exercises/dominoes/domino.rb @@ -1,6 +1,10 @@ class Domino attr_reader :left, :right + def self.deep_copy(domino) + Domino.new(domino.left, domino.right) + end + def initialize(left, right) @left = left @right = right diff --git a/exercises/dominoes/dominoes.rb b/exercises/dominoes/dominoes.rb index f76c8f1964..e10b092b6d 100644 --- a/exercises/dominoes/dominoes.rb +++ b/exercises/dominoes/dominoes.rb @@ -2,12 +2,14 @@ class Dominoes require_relative 'domino' attr_accessor :list - #[ArrayTuples] => [Domino] - def initialize(arr_form_of_dominoes =[]) + #[ArrayTuples], false => [Domino] or [Domino], true => [Domino] + def initialize( arr=[], already_dominoes= nil) @list = [] - if !arr_form_of_dominoes.empty? - arr_form_of_dominoes.each do |item| + arr.each do |item| + if !already_dominoes @list << Domino.new(item[0], item[1]) + else + @list << Domino.deep_copy(item) end end end @@ -37,7 +39,7 @@ def first # result # end - + # def self.make_dominoes!(arr_form_of_dominoes =[]) # @list = []