From 567c27854a1ce8fe0709c83939aee5750c37a3c9 Mon Sep 17 00:00:00 2001 From: emilybache Date: Mon, 10 Jun 2013 14:42:41 +0200 Subject: [PATCH] Removed all the code except for the GildedRose kata from this repo --- {GildedRose/C => C}/GildedRose.c | 0 {GildedRose/C => C}/GildedRose.h | 0 {GildedRose/C => C}/GildedRoseTextTests.c | 0 {GildedRose/C => C}/GildedRoseUnitTests.cc | 0 {GildedRose/C => C}/Makefile | 0 {GildedRose/C => C}/README | 0 {GildedRose/C => C}/run-once.sh | 0 GildedRose/.gitignore | 1 - GildedRose/README.md | 40 --- GildedRose/texttests/.DS_Store | Bin 6148 -> 0 bytes ...irements.txt => GildedRoseRequirements.txt | 0 .../com/gildedrose/GildedRose.java | 0 .../com/gildedrose/GildedRoseTest.java | 0 .../Java => Java}/com/gildedrose/Item.java | 0 .../com/gildedrose/TexttestFixture.java | 0 README.md | 43 ++- .../Smalltalk => Smalltalk}/GildedRose.st | 0 Tennis/README.md | 30 -- Tennis/cpp/all_tests.cpp | 171 ---------- Tennis/cpp/all_tests.hpp | 33 -- Tennis/cpp/generate_tests.py | 79 ----- Tennis/cpp/makefile | 5 - Tennis/cpp/tennis1.cc | 61 ---- Tennis/cpp/tennis2.cc | 92 ------ Tennis/cpp/tennis3.cc | 17 - Tennis/cpp/test_suite.tests.cpp | 55 ---- Tennis/csharp/AssemblyInfo.cs | 27 -- Tennis/csharp/Main.cs | 12 - Tennis/csharp/Tennis.csproj | 48 --- Tennis/csharp/TennisGame.cs | 12 - Tennis/csharp/TennisGame1.cs | 89 ----- Tennis/csharp/TennisGame2.cs | 144 --------- Tennis/csharp/TennisGame3.cs | 41 --- Tennis/csharp/TennisTest.cs | 115 ------- Tennis/java/TennisGame.java | 5 - Tennis/java/TennisGame1.java | 79 ----- Tennis/java/TennisGame2.java | 137 -------- Tennis/java/TennisGame3.java | 36 --- Tennis/java/TennisTest.java | 98 ------ Tennis/objc/.gitignore | 3 - Tennis/objc/Tennis.xcodeproj/project.pbxproj | 305 ------------------ .../contents.xcworkspacedata | 7 - .../xcschemes/TennisTests.xcscheme | 68 ---- Tennis/objc/Tennis/TennisGame.h | 9 - Tennis/objc/Tennis/TennisGame.m | 10 - Tennis/objc/Tennis/TennisGame1.h | 5 - Tennis/objc/Tennis/TennisGame1.m | 92 ------ Tennis/objc/Tennis/TennisGame2.h | 5 - Tennis/objc/Tennis/TennisGame2.m | 147 --------- Tennis/objc/Tennis/TennisGame3.h | 5 - Tennis/objc/Tennis/TennisGame3.m | 46 --- Tennis/objc/TennisTests/TennisTests.h | 5 - Tennis/objc/TennisTests/TennisTests.m | 121 ------- Tennis/python/tennis.py | 175 ---------- Tennis/python/tennis_test.py | 23 -- Tennis/python/tennis_unittest.py | 85 ----- Tennis/ruby/tennis.rb | 223 ------------- Tennis/ruby/tennis_test.rb | 86 ----- Yahtzee/README.md | 116 ------- Yahtzee/cpp/makefile | 6 - Yahtzee/cpp/run.tests | Bin 24820 -> 0 bytes Yahtzee/cpp/yahtzee.cpp | 251 -------------- Yahtzee/cpp/yahtzee.hpp | 33 -- Yahtzee/cpp/yahtzee.tests.cpp | 153 --------- Yahtzee/csharp/Yahtzee.cs | 238 -------------- Yahtzee/csharp/YahtzeeTest.cs | 124 ------- Yahtzee/java/Yahtzee.java | 241 -------------- Yahtzee/java/YahtzeeTest.java | 110 ------- Yahtzee/python/test_yahtzee.py | 94 ------ Yahtzee/python/yahtzee.py | 230 ------------- Yahtzee/ruby/test_yahtzee.rb | 94 ------ Yahtzee/ruby/yahtzee.rb | 256 --------------- {GildedRose/cpp => cpp}/GildedRose.cc | 0 {GildedRose/cpp => cpp}/GildedRose.h | 0 .../cpp => cpp}/GildedRoseTextTests.cc | 0 .../cpp => cpp}/GildedRoseUnitTests.cc | 0 {GildedRose/cpp => cpp}/Makefile | 0 {GildedRose/cpp => cpp}/README | 0 {GildedRose/cpp => cpp}/run-once.sh | 0 {GildedRose/csharp => csharp}/ApprovalTest.cs | 0 {GildedRose/csharp => csharp}/GildedRose.cs | 0 .../csharp => csharp}/GildedRoseTest.cs | 0 .../csharp => csharp}/TextTestFixture.cs | 0 {GildedRose/js => js}/.gitignore | 0 {GildedRose/js => js}/README.md | 0 {GildedRose/js => js}/SpecRunner.html | 0 .../js => js}/lib/jasmine-1.1.0/MIT.LICENSE | 0 .../lib/jasmine-1.1.0/jasmine-html.js | 0 .../js => js}/lib/jasmine-1.1.0/jasmine.css | 0 .../js => js}/lib/jasmine-1.1.0/jasmine.js | 0 .../lib/jasmine-1.1.0/jasmine_favicon.png | Bin .../js => js}/lib/jasmine-ajax/mock-ajax.js | 0 .../jasmine-jquery-1.3.1.js | 0 .../lib/jquery-1.7.1/jquery-1.7.1.js | 0 .../js => js}/spec/gilded_rose_spec.js | 0 {GildedRose/js => js}/src/gilded_rose.js | 0 {GildedRose/python => python}/gilded_rose.py | 0 .../python => python}/test_gilded_rose.py | 0 .../python => python}/texttest_fixture.py | 0 {GildedRose/ruby => ruby}/.rspec | 0 {GildedRose/ruby => ruby}/gilded_rose.rb | 0 {GildedRose/ruby => ruby}/gilded_rose_spec.rb | 0 .../ruby => ruby}/gilded_rose_tests.rb | 0 {GildedRose/ruby => ruby}/texttest_fixture.rb | 0 {GildedRose/texttests => texttests}/README.md | 0 .../ThirtyDays/._options.gr | Bin .../ThirtyDays/options.gr | 0 .../ThirtyDays/stderr.gr | 0 .../ThirtyDays/stdout.gr | 0 {GildedRose/texttests => texttests}/config.gr | 0 .../texttests => texttests}/environment.gr | 0 .../texttests => texttests}/testsuite.gr | 0 112 files changed, 35 insertions(+), 4801 deletions(-) rename {GildedRose/C => C}/GildedRose.c (100%) rename {GildedRose/C => C}/GildedRose.h (100%) rename {GildedRose/C => C}/GildedRoseTextTests.c (100%) rename {GildedRose/C => C}/GildedRoseUnitTests.cc (100%) rename {GildedRose/C => C}/Makefile (100%) rename {GildedRose/C => C}/README (100%) rename {GildedRose/C => C}/run-once.sh (100%) delete mode 100644 GildedRose/.gitignore delete mode 100644 GildedRose/README.md delete mode 100644 GildedRose/texttests/.DS_Store rename GildedRose/GildedRoseRequirements.txt => GildedRoseRequirements.txt (100%) rename {GildedRose/Java => Java}/com/gildedrose/GildedRose.java (100%) rename {GildedRose/Java => Java}/com/gildedrose/GildedRoseTest.java (100%) rename {GildedRose/Java => Java}/com/gildedrose/Item.java (100%) rename {GildedRose/Java => Java}/com/gildedrose/TexttestFixture.java (100%) rename {GildedRose/Smalltalk => Smalltalk}/GildedRose.st (100%) delete mode 100644 Tennis/README.md delete mode 100644 Tennis/cpp/all_tests.cpp delete mode 100644 Tennis/cpp/all_tests.hpp delete mode 100644 Tennis/cpp/generate_tests.py delete mode 100644 Tennis/cpp/makefile delete mode 100644 Tennis/cpp/tennis1.cc delete mode 100644 Tennis/cpp/tennis2.cc delete mode 100644 Tennis/cpp/tennis3.cc delete mode 100644 Tennis/cpp/test_suite.tests.cpp delete mode 100644 Tennis/csharp/AssemblyInfo.cs delete mode 100644 Tennis/csharp/Main.cs delete mode 100644 Tennis/csharp/Tennis.csproj delete mode 100644 Tennis/csharp/TennisGame.cs delete mode 100644 Tennis/csharp/TennisGame1.cs delete mode 100644 Tennis/csharp/TennisGame2.cs delete mode 100644 Tennis/csharp/TennisGame3.cs delete mode 100644 Tennis/csharp/TennisTest.cs delete mode 100644 Tennis/java/TennisGame.java delete mode 100644 Tennis/java/TennisGame1.java delete mode 100644 Tennis/java/TennisGame2.java delete mode 100644 Tennis/java/TennisGame3.java delete mode 100644 Tennis/java/TennisTest.java delete mode 100644 Tennis/objc/.gitignore delete mode 100644 Tennis/objc/Tennis.xcodeproj/project.pbxproj delete mode 100644 Tennis/objc/Tennis.xcodeproj/project.xcworkspace/contents.xcworkspacedata delete mode 100644 Tennis/objc/Tennis.xcodeproj/xcshareddata/xcschemes/TennisTests.xcscheme delete mode 100644 Tennis/objc/Tennis/TennisGame.h delete mode 100644 Tennis/objc/Tennis/TennisGame.m delete mode 100644 Tennis/objc/Tennis/TennisGame1.h delete mode 100644 Tennis/objc/Tennis/TennisGame1.m delete mode 100644 Tennis/objc/Tennis/TennisGame2.h delete mode 100644 Tennis/objc/Tennis/TennisGame2.m delete mode 100644 Tennis/objc/Tennis/TennisGame3.h delete mode 100644 Tennis/objc/Tennis/TennisGame3.m delete mode 100644 Tennis/objc/TennisTests/TennisTests.h delete mode 100644 Tennis/objc/TennisTests/TennisTests.m delete mode 100644 Tennis/python/tennis.py delete mode 100644 Tennis/python/tennis_test.py delete mode 100644 Tennis/python/tennis_unittest.py delete mode 100644 Tennis/ruby/tennis.rb delete mode 100644 Tennis/ruby/tennis_test.rb delete mode 100644 Yahtzee/README.md delete mode 100644 Yahtzee/cpp/makefile delete mode 100755 Yahtzee/cpp/run.tests delete mode 100644 Yahtzee/cpp/yahtzee.cpp delete mode 100644 Yahtzee/cpp/yahtzee.hpp delete mode 100644 Yahtzee/cpp/yahtzee.tests.cpp delete mode 100644 Yahtzee/csharp/Yahtzee.cs delete mode 100644 Yahtzee/csharp/YahtzeeTest.cs delete mode 100644 Yahtzee/java/Yahtzee.java delete mode 100644 Yahtzee/java/YahtzeeTest.java delete mode 100644 Yahtzee/python/test_yahtzee.py delete mode 100644 Yahtzee/python/yahtzee.py delete mode 100644 Yahtzee/ruby/test_yahtzee.rb delete mode 100644 Yahtzee/ruby/yahtzee.rb rename {GildedRose/cpp => cpp}/GildedRose.cc (100%) rename {GildedRose/cpp => cpp}/GildedRose.h (100%) rename {GildedRose/cpp => cpp}/GildedRoseTextTests.cc (100%) rename {GildedRose/cpp => cpp}/GildedRoseUnitTests.cc (100%) rename {GildedRose/cpp => cpp}/Makefile (100%) rename {GildedRose/cpp => cpp}/README (100%) rename {GildedRose/cpp => cpp}/run-once.sh (100%) rename {GildedRose/csharp => csharp}/ApprovalTest.cs (100%) rename {GildedRose/csharp => csharp}/GildedRose.cs (100%) rename {GildedRose/csharp => csharp}/GildedRoseTest.cs (100%) rename {GildedRose/csharp => csharp}/TextTestFixture.cs (100%) rename {GildedRose/js => js}/.gitignore (100%) rename {GildedRose/js => js}/README.md (100%) rename {GildedRose/js => js}/SpecRunner.html (100%) rename {GildedRose/js => js}/lib/jasmine-1.1.0/MIT.LICENSE (100%) rename {GildedRose/js => js}/lib/jasmine-1.1.0/jasmine-html.js (100%) rename {GildedRose/js => js}/lib/jasmine-1.1.0/jasmine.css (100%) rename {GildedRose/js => js}/lib/jasmine-1.1.0/jasmine.js (100%) rename {GildedRose/js => js}/lib/jasmine-1.1.0/jasmine_favicon.png (100%) rename {GildedRose/js => js}/lib/jasmine-ajax/mock-ajax.js (100%) rename {GildedRose/js => js}/lib/jasmine-jquery-1.3.1/jasmine-jquery-1.3.1.js (100%) rename {GildedRose/js => js}/lib/jquery-1.7.1/jquery-1.7.1.js (100%) rename {GildedRose/js => js}/spec/gilded_rose_spec.js (100%) rename {GildedRose/js => js}/src/gilded_rose.js (100%) rename {GildedRose/python => python}/gilded_rose.py (100%) rename {GildedRose/python => python}/test_gilded_rose.py (100%) rename {GildedRose/python => python}/texttest_fixture.py (100%) rename {GildedRose/ruby => ruby}/.rspec (100%) rename {GildedRose/ruby => ruby}/gilded_rose.rb (100%) rename {GildedRose/ruby => ruby}/gilded_rose_spec.rb (100%) rename {GildedRose/ruby => ruby}/gilded_rose_tests.rb (100%) rename {GildedRose/ruby => ruby}/texttest_fixture.rb (100%) rename {GildedRose/texttests => texttests}/README.md (100%) rename {GildedRose/texttests => texttests}/ThirtyDays/._options.gr (100%) rename {GildedRose/texttests => texttests}/ThirtyDays/options.gr (100%) rename {GildedRose/texttests => texttests}/ThirtyDays/stderr.gr (100%) rename {GildedRose/texttests => texttests}/ThirtyDays/stdout.gr (100%) rename {GildedRose/texttests => texttests}/config.gr (100%) rename {GildedRose/texttests => texttests}/environment.gr (100%) rename {GildedRose/texttests => texttests}/testsuite.gr (100%) diff --git a/GildedRose/C/GildedRose.c b/C/GildedRose.c similarity index 100% rename from GildedRose/C/GildedRose.c rename to C/GildedRose.c diff --git a/GildedRose/C/GildedRose.h b/C/GildedRose.h similarity index 100% rename from GildedRose/C/GildedRose.h rename to C/GildedRose.h diff --git a/GildedRose/C/GildedRoseTextTests.c b/C/GildedRoseTextTests.c similarity index 100% rename from GildedRose/C/GildedRoseTextTests.c rename to C/GildedRoseTextTests.c diff --git a/GildedRose/C/GildedRoseUnitTests.cc b/C/GildedRoseUnitTests.cc similarity index 100% rename from GildedRose/C/GildedRoseUnitTests.cc rename to C/GildedRoseUnitTests.cc diff --git a/GildedRose/C/Makefile b/C/Makefile similarity index 100% rename from GildedRose/C/Makefile rename to C/Makefile diff --git a/GildedRose/C/README b/C/README similarity index 100% rename from GildedRose/C/README rename to C/README diff --git a/GildedRose/C/run-once.sh b/C/run-once.sh similarity index 100% rename from GildedRose/C/run-once.sh rename to C/run-once.sh diff --git a/GildedRose/.gitignore b/GildedRose/.gitignore deleted file mode 100644 index 7e99e367..00000000 --- a/GildedRose/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.pyc \ No newline at end of file diff --git a/GildedRose/README.md b/GildedRose/README.md deleted file mode 100644 index 39e1616e..00000000 --- a/GildedRose/README.md +++ /dev/null @@ -1,40 +0,0 @@ -This Kata was originally created by Terry Hughes (http://twitter.com/#!/TerryHughes). It is already on GitHub [here](https://github.com/NotMyself/GildedRose). See also [Bobby Johnson's description of the kata](http://iamnotmyself.com/2011/02/13/refactor-this-the-gilded-rose-kata/). - -I translated the original C# into a few other languages, (with a little help from my friends!), and slightly changed the starting position. This means I've actually done a small amount of refactoring already compared with the original form of the kata, and made it easier to get going with writing tests by giving you one failing unit test to start with. I also added test fixtures for Text-Based approval testing with TextTest (see [the TextTests](https://github.com/emilybache/Refactoring-Katas/tree/master/GildedRose/texttests)) - -As Bobby Johnson points out in his article ["Why Most Solutions to Gilded Rose Miss The Bigger Picture"](http://iamnotmyself.com/2012/12/07/why-most-solutions-to-gilded-rose-miss-the-bigger-picture/), it'll actually give you -better practice at handling a legacy code situation if you do this Kata in the original C#. However, I think this kata -is also really useful for practicing writing good tests using different frameworks and approaches, and the small changes I've made help with that. I think it's also interesting to compare what the refactored code and tests look like in different programming languages. - -I wrote this article ["Writing Good Tests for the Gilded Rose Kata"](http://emilybache.blogspot.se/2013/03/writing-good-tests-for-gilded-rose-kata.html) about how you could use this kata in a [coding dojo](https://leanpub.com/codingdojohandbook). - -## How to use this Kata - -The simplest way is to just clone the code and start hacking away improving the design. You'll want to look at the ["Gilded Rose Requirements"](https://github.com/emilybache/Refactoring-Katas/blob/master/GildedRose/GildedRoseRequirements.txt) which explains what the code is for. I strongly advise you that you'll also need some tests if you want to make sure you don't break the code while you refactor. - -You could write some unit tests yourself, using the requirements to identify suitable test cases. I've provided a failing unit test in a popular test framework as a starting point for most languages. - -Alternatively, use the "Text-Based" tests provided in this repository. (Read more about that in the next section) - -Whichever testing approach you choose, the idea of the exercise is to do some deliberate practice, and improve your skills at designing test cases and refactoring. The idea is not to re-write the code from scratch, but rather to practice designing tests, taking small steps, running the tests often, and incrementally improving the design. - -## Text-Based Approval Testing - -This is a testing approach which is very useful when refactoring legacy code. Before you change the code, you run it, and gather the output of the code as a plain text file. You review the text, and if it correctly describes the behaviour as you understand it, you can "approve" it, and save it as a "Golden Master". Then after you change the code, you run it again, and compare the new output against the Golden Master. Any differences, and the test fails. - -It's basically the same idea as "assertEquals(expected, actual)" in a unit test, except the text you are comparing is typically much longer, and the "expected" value is saved from actual output, rather than being defined in advance. - -Typically a piece of legacy code may not produce suitable textual output from the start, so you may need to modify it before you can write your first text-based approval test. That could involve inserting log statements into the code, or just writing a "main" method that executes the code and prints out what the result is afterwards. It's this latter approach we are using here to test GildedRose. - -The Text-Based tests in this repository are designed to be used with the tool "TextTest" (http://texttest.org). This tool helps you to organize and run text-based tests. There is more information in the README file in the "texttests" subdirectory. - -## Get going quickly using Cyber-Dojo - -I've also set this kata up on [cyber-dojo](http://cyber-dojo.com) for several languages, so you can get going really quickly: - -- [JUnit, Java](http://cyber-dojo.com/forker/fork/751DD02C4C?avatar=snake&tag=4) -- [C#](http://cyber-dojo.com/forker/fork/107907AD1E?avatar=alligator&tag=13) -- [Ruby](http://cyber-dojo.com/forker/fork/A8943EAF92?avatar=hippo&tag=9) -- [RSpec, Ruby](http://cyber-dojo.com/forker/fork/8E58B0AD16?avatar=raccoon&tag=3) -- [Python](http://cyber-dojo.com/forker/fork/297041AA7A?avatar=lion&tag=4) -- [Cucumber, Java](http://cyber-dojo.com/forker/fork/0F82D4BA89?avatar=gorilla&tag=45) - for this one I've also written some step definitions for you diff --git a/GildedRose/texttests/.DS_Store b/GildedRose/texttests/.DS_Store deleted file mode 100644 index d01643f900f685a498b539a8e9c9ab7ffd74e89f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKJ5Iw;5S)b+5i}_&-vMa2ffbpKE*t=`C4%J05lIR<1L&q@{oz zX?L9U?6W+DHw!@KyY>p00hltB@v3PIy{|FCNmNeBVrOjef*SYCo00l(L3__|izS}$ zjJ^JL({vAg-|^tXg06pDH2rGr=U(0%)2;ftZg<-T_;_EwxjJ(?kPf5+=|DR0e;v@# zN=(n4Gp7UTKsxa4fPNneL%9kbobA)WWGeu9!m@$awo8zU7RXib;LHjk-b(gXi4{Y< zo%IsBDtK`Ac1SEA5>J-cP{f|j^NYzLm2>8FARYMWfbQPJOy~bK*zIg))vMc;|tW9oXJKp*+wyc=qSF}(-pnu{VI5HwszL7ot%FJ)R#m$ I@EZ<%0y*0zSpWb4 diff --git a/GildedRose/GildedRoseRequirements.txt b/GildedRoseRequirements.txt similarity index 100% rename from GildedRose/GildedRoseRequirements.txt rename to GildedRoseRequirements.txt diff --git a/GildedRose/Java/com/gildedrose/GildedRose.java b/Java/com/gildedrose/GildedRose.java similarity index 100% rename from GildedRose/Java/com/gildedrose/GildedRose.java rename to Java/com/gildedrose/GildedRose.java diff --git a/GildedRose/Java/com/gildedrose/GildedRoseTest.java b/Java/com/gildedrose/GildedRoseTest.java similarity index 100% rename from GildedRose/Java/com/gildedrose/GildedRoseTest.java rename to Java/com/gildedrose/GildedRoseTest.java diff --git a/GildedRose/Java/com/gildedrose/Item.java b/Java/com/gildedrose/Item.java similarity index 100% rename from GildedRose/Java/com/gildedrose/Item.java rename to Java/com/gildedrose/Item.java diff --git a/GildedRose/Java/com/gildedrose/TexttestFixture.java b/Java/com/gildedrose/TexttestFixture.java similarity index 100% rename from GildedRose/Java/com/gildedrose/TexttestFixture.java rename to Java/com/gildedrose/TexttestFixture.java diff --git a/README.md b/README.md index 48d83c49..e823a9a5 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,40 @@ -# Refactoring Katas +This Kata was originally created by Terry Hughes (http://twitter.com/#!/TerryHughes). It is already on GitHub [here](https://github.com/NotMyself/GildedRose). See also [Bobby Johnson's description of the kata](http://iamnotmyself.com/2011/02/13/refactor-this-the-gilded-rose-kata/). -Can you refactor? In really small steps? Can you turn some, frankly, ugly code into a paradigm of elegant, readable, extensible design? +I translated the original C# into a few other languages, (with a little help from my friends!), and slightly changed the starting position. This means I've actually done a small amount of refactoring already compared with the original form of the kata, and made it easier to get going with writing tests by giving you one failing unit test to start with. I also added test fixtures for Text-Based approval testing with TextTest (see [the TextTests](https://github.com/emilybache/GildedRose-Refactoring-Kata/tree/master/texttests)) -This is a collection of starting files for when practicing refactoring. +As Bobby Johnson points out in his article ["Why Most Solutions to Gilded Rose Miss The Bigger Picture"](http://iamnotmyself.com/2012/12/07/why-most-solutions-to-gilded-rose-miss-the-bigger-picture/), it'll actually give you +better practice at handling a legacy code situation if you do this Kata in the original C#. However, I think this kata +is also really useful for practicing writing good tests using different frameworks and approaches, and the small changes I've made help with that. I think it's also interesting to compare what the refactored code and tests look like in different programming languages. -Contents so far: +I wrote this article ["Writing Good Tests for the Gilded Rose Kata"](http://emilybache.blogspot.se/2013/03/writing-good-tests-for-gilded-rose-kata.html) about how you could use this kata in a [coding dojo](https://leanpub.com/codingdojohandbook). -- Tennis Kata in Java, Python, Objective-C and C++. -- Gilded Rose Kata in C++, C#, Java, Python, Smalltalk, C and Ruby. (a C# version together with a starting project is already available on github [here](https://github.com/NotMyself/GildedRose)) -- Yahtzee Kata in C#, Java, C++ and Python (the C#, C++ and Java versions are also available in Jon Jagger's Cyberdojo, see [his blog post](http://jonjagger.blogspot.co.uk/2012/05/yahtzee-cyber-dojo-refactoring-in-java.html)) +## How to use this Kata -For more information about these and other katas, you may be interested in my book [The Coding Dojo Handbook](http://leanpub.com/codingdojohandbook) \ No newline at end of file +The simplest way is to just clone the code and start hacking away improving the design. You'll want to look at the ["Gilded Rose Requirements"](https://github.com/emilybache/GildedRose-Refactoring-Kata/tree/master/GildedRoseRequirements.txt) which explains what the code is for. I strongly advise you that you'll also need some tests if you want to make sure you don't break the code while you refactor. + +You could write some unit tests yourself, using the requirements to identify suitable test cases. I've provided a failing unit test in a popular test framework as a starting point for most languages. + +Alternatively, use the "Text-Based" tests provided in this repository. (Read more about that in the next section) + +Whichever testing approach you choose, the idea of the exercise is to do some deliberate practice, and improve your skills at designing test cases and refactoring. The idea is not to re-write the code from scratch, but rather to practice designing tests, taking small steps, running the tests often, and incrementally improving the design. + +## Text-Based Approval Testing + +This is a testing approach which is very useful when refactoring legacy code. Before you change the code, you run it, and gather the output of the code as a plain text file. You review the text, and if it correctly describes the behaviour as you understand it, you can "approve" it, and save it as a "Golden Master". Then after you change the code, you run it again, and compare the new output against the Golden Master. Any differences, and the test fails. + +It's basically the same idea as "assertEquals(expected, actual)" in a unit test, except the text you are comparing is typically much longer, and the "expected" value is saved from actual output, rather than being defined in advance. + +Typically a piece of legacy code may not produce suitable textual output from the start, so you may need to modify it before you can write your first text-based approval test. That could involve inserting log statements into the code, or just writing a "main" method that executes the code and prints out what the result is afterwards. It's this latter approach we are using here to test GildedRose. + +The Text-Based tests in this repository are designed to be used with the tool "TextTest" (http://texttest.org). This tool helps you to organize and run text-based tests. There is more information in the README file in the "texttests" subdirectory. + +## Get going quickly using Cyber-Dojo + +I've also set this kata up on [cyber-dojo](http://cyber-dojo.com) for several languages, so you can get going really quickly: + +- [JUnit, Java](http://cyber-dojo.com/forker/fork/751DD02C4C?avatar=snake&tag=4) +- [C#](http://cyber-dojo.com/forker/fork/107907AD1E?avatar=alligator&tag=13) +- [Ruby](http://cyber-dojo.com/forker/fork/A8943EAF92?avatar=hippo&tag=9) +- [RSpec, Ruby](http://cyber-dojo.com/forker/fork/8E58B0AD16?avatar=raccoon&tag=3) +- [Python](http://cyber-dojo.com/forker/fork/297041AA7A?avatar=lion&tag=4) +- [Cucumber, Java](http://cyber-dojo.com/forker/fork/0F82D4BA89?avatar=gorilla&tag=45) - for this one I've also written some step definitions for you diff --git a/GildedRose/Smalltalk/GildedRose.st b/Smalltalk/GildedRose.st similarity index 100% rename from GildedRose/Smalltalk/GildedRose.st rename to Smalltalk/GildedRose.st diff --git a/Tennis/README.md b/Tennis/README.md deleted file mode 100644 index 3349351d..00000000 --- a/Tennis/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# Tennis Refactoring Kata - -Imagine you work for a consultancy company, and one of your colleagues has been doing some work for the Tennis Society. The contract is for 10 hours billable work, and your colleague has spent 8.5 hours working on it. Unfortunately he has now fallen ill. He says he has completed the work, and the tests all pass. Your boss has asked you to take over from him. She wants you to spend an hour or so on the code so she can bill the client for the full 10 hours. She instructs you to tidy up the code a little and perhaps make some notes so you can give your colleague some feedback on his chosen design. - -There are three versions of this refactoring kata, each with their own design smells and challenges. I suggest you start with the first one. The test suite provided is fairly comprehensive, and fast to run. You should not need to change the tests, only run them often as you refactor. - -## Tennis Kata - -Tennis has a rather quirky scoring system, and to newcomers it can be a little difficult to keep track of. The tennis society has contracted you to build a scoreboard to display the current score during tennis games. - -Your task is to write a “TennisGame” class containing the logic which outputs the correct score as a string for display on the scoreboard. When a player scores a point, it triggers a method to be called on your class letting you know who scored the point. Later, you will get a call “score()” from the scoreboard asking what it should display. This method should return a string with the current score. - -You can read more about Tennis scores [here](http://en.wikipedia.org/wiki/Tennis#Scoring) which is summarized below: - -1. A game is won by the first player to have won at least four points in total and at least two points more than the opponent. -2. The running score of each game is described in a manner peculiar to tennis: scores from zero to three points are described as "love", "fifteen", "thirty", and "forty" respectively. -3. If at least three points have been scored by each player, and the scores are equal, the score is "deuce". -4. If at least three points have been scored by each side and a player has one more point than his opponent, the score of the game is "advantage" for the player in the lead. - -You need only report the score for the current game. Sets and Matches are out of scope. - -# Get going quickly with Cyber-dojo - -As an alternative to downloading the code, click one of the links below to create a new cyber-dojo to work in, then press "start" to get going coding. - -- [Python](http://cyber-dojo.com/forker/fork/FFEB8EE18C?avatar=cheetah&tag=4) -- [Ruby](http://cyber-dojo.com/forker/fork/9197D6B12C?avatar=cheetah&tag=4) -- [Java](http://cyber-dojo.com/forker/fork/426FA07B60?avatar=raccoon&tag=3) -- [C++](http://cyber-dojo.com/forker/fork/CD6FC41518?avatar=deer&tag=45) -- [C#](http://cyber-dojo.com/forker/fork/672E047F5D?avatar=buffalo&tag=8) \ No newline at end of file diff --git a/Tennis/cpp/all_tests.cpp b/Tennis/cpp/all_tests.cpp deleted file mode 100644 index c677cfdc..00000000 --- a/Tennis/cpp/all_tests.cpp +++ /dev/null @@ -1,171 +0,0 @@ -#include "all_tests.hpp" - -/* change this to the version of tennis you want to work on */ -#include "tennis1.cc" - -#include - -void test_LoveAll_0_0() -{ - assert("Love-All" == tennis_score(0, 0)); -} - -void test_FifteenAll_1_1() -{ - assert("Fifteen-All" == tennis_score(1, 1)); -} - -void test_ThirtyAll_2_2() -{ - assert("Thirty-All" == tennis_score(2, 2)); -} - -void test_Deuce_3_3() -{ - assert("Deuce" == tennis_score(3, 3)); -} - -void test_Deuce_4_4() -{ - assert("Deuce" == tennis_score(4, 4)); -} - -void test_FifteenLove_1_0() -{ - assert("Fifteen-Love" == tennis_score(1, 0)); -} - -void test_LoveFifteen_0_1() -{ - assert("Love-Fifteen" == tennis_score(0, 1)); -} - -void test_ThirtyLove_2_0() -{ - assert("Thirty-Love" == tennis_score(2, 0)); -} - -void test_LoveThirty_0_2() -{ - assert("Love-Thirty" == tennis_score(0, 2)); -} - -void test_FortyLove_3_0() -{ - assert("Forty-Love" == tennis_score(3, 0)); -} - -void test_LoveForty_0_3() -{ - assert("Love-Forty" == tennis_score(0, 3)); -} - -void test_Winforplayer1_4_0() -{ - assert("Win for player1" == tennis_score(4, 0)); -} - -void test_Winforplayer2_0_4() -{ - assert("Win for player2" == tennis_score(0, 4)); -} - -void test_ThirtyFifteen_2_1() -{ - assert("Thirty-Fifteen" == tennis_score(2, 1)); -} - -void test_FifteenThirty_1_2() -{ - assert("Fifteen-Thirty" == tennis_score(1, 2)); -} - -void test_FortyFifteen_3_1() -{ - assert("Forty-Fifteen" == tennis_score(3, 1)); -} - -void test_FifteenForty_1_3() -{ - assert("Fifteen-Forty" == tennis_score(1, 3)); -} - -void test_Winforplayer1_4_1() -{ - assert("Win for player1" == tennis_score(4, 1)); -} - -void test_Winforplayer2_1_4() -{ - assert("Win for player2" == tennis_score(1, 4)); -} - -void test_FortyThirty_3_2() -{ - assert("Forty-Thirty" == tennis_score(3, 2)); -} - -void test_ThirtyForty_2_3() -{ - assert("Thirty-Forty" == tennis_score(2, 3)); -} - -void test_Winforplayer1_4_2() -{ - assert("Win for player1" == tennis_score(4, 2)); -} - -void test_Winforplayer2_2_4() -{ - assert("Win for player2" == tennis_score(2, 4)); -} - -void test_Advantageplayer1_4_3() -{ - assert("Advantage player1" == tennis_score(4, 3)); -} - -void test_Advantageplayer2_3_4() -{ - assert("Advantage player2" == tennis_score(3, 4)); -} - -void test_Advantageplayer1_5_4() -{ - assert("Advantage player1" == tennis_score(5, 4)); -} - -void test_Advantageplayer2_4_5() -{ - assert("Advantage player2" == tennis_score(4, 5)); -} - -void test_Advantageplayer1_15_14() -{ - assert("Advantage player1" == tennis_score(15, 14)); -} - -void test_Advantageplayer2_14_15() -{ - assert("Advantage player2" == tennis_score(14, 15)); -} - -void test_Winforplayer1_6_4() -{ - assert("Win for player1" == tennis_score(6, 4)); -} - -void test_Winforplayer2_4_6() -{ - assert("Win for player2" == tennis_score(4, 6)); -} - -void test_Winforplayer1_16_14() -{ - assert("Win for player1" == tennis_score(16, 14)); -} - -void test_Winforplayer2_14_16() -{ - assert("Win for player2" == tennis_score(14, 16)); -} \ No newline at end of file diff --git a/Tennis/cpp/all_tests.hpp b/Tennis/cpp/all_tests.hpp deleted file mode 100644 index b0fed07f..00000000 --- a/Tennis/cpp/all_tests.hpp +++ /dev/null @@ -1,33 +0,0 @@ -void test_LoveAll_0_0(); -void test_FifteenAll_1_1(); -void test_ThirtyAll_2_2(); -void test_Deuce_3_3(); -void test_Deuce_4_4(); -void test_FifteenLove_1_0(); -void test_LoveFifteen_0_1(); -void test_ThirtyLove_2_0(); -void test_LoveThirty_0_2(); -void test_FortyLove_3_0(); -void test_LoveForty_0_3(); -void test_Winforplayer1_4_0(); -void test_Winforplayer2_0_4(); -void test_ThirtyFifteen_2_1(); -void test_FifteenThirty_1_2(); -void test_FortyFifteen_3_1(); -void test_FifteenForty_1_3(); -void test_Winforplayer1_4_1(); -void test_Winforplayer2_1_4(); -void test_FortyThirty_3_2(); -void test_ThirtyForty_2_3(); -void test_Winforplayer1_4_2(); -void test_Winforplayer2_2_4(); -void test_Advantageplayer1_4_3(); -void test_Advantageplayer2_3_4(); -void test_Advantageplayer1_5_4(); -void test_Advantageplayer2_4_5(); -void test_Advantageplayer1_15_14(); -void test_Advantageplayer2_14_15(); -void test_Winforplayer1_6_4(); -void test_Winforplayer2_4_6(); -void test_Winforplayer1_16_14(); -void test_Winforplayer2_14_16(); \ No newline at end of file diff --git a/Tennis/cpp/generate_tests.py b/Tennis/cpp/generate_tests.py deleted file mode 100644 index d2f2c585..00000000 --- a/Tennis/cpp/generate_tests.py +++ /dev/null @@ -1,79 +0,0 @@ - - -test_cases = [dict(p1Points=0, p2Points=0, score="Love-All"), - dict(p1Points=1, p2Points=1, score="Fifteen-All"), - dict(p1Points=2, p2Points=2, score="Thirty-All"), - dict(p1Points=3, p2Points=3, score="Deuce"), - dict(p1Points=4, p2Points=4, score="Deuce"), - - dict(p1Points=1, p2Points=0, score="Fifteen-Love"), - dict(p1Points=0, p2Points=1, score="Love-Fifteen"), - dict(p1Points=2, p2Points=0, score="Thirty-Love"), - dict(p1Points=0, p2Points=2, score="Love-Thirty"), - dict(p1Points=3, p2Points=0, score="Forty-Love"), - dict(p1Points=0, p2Points=3, score="Love-Forty"), - dict(p1Points=4, p2Points=0, score="Win for player1"), - dict(p1Points=0, p2Points=4, score="Win for player2"), - - dict(p1Points=2, p2Points=1, score="Thirty-Fifteen"), - dict(p1Points=1, p2Points=2, score="Fifteen-Thirty"), - dict(p1Points=3, p2Points=1, score="Forty-Fifteen"), - dict(p1Points=1, p2Points=3, score="Fifteen-Forty"), - dict(p1Points=4, p2Points=1, score="Win for player1"), - dict(p1Points=1, p2Points=4, score="Win for player2"), - - dict(p1Points=3, p2Points=2, score="Forty-Thirty"), - dict(p1Points=2, p2Points=3, score="Thirty-Forty"), - dict(p1Points=4, p2Points=2, score="Win for player1"), - dict(p1Points=2, p2Points=4, score="Win for player2"), - - dict(p1Points=4, p2Points=3, score="Advantage player1"), - dict(p1Points=3, p2Points=4, score="Advantage player2"), - dict(p1Points=5, p2Points=4, score="Advantage player1"), - dict(p1Points=4, p2Points=5, score="Advantage player2"), - dict(p1Points=15, p2Points=14, score="Advantage player1"), - dict(p1Points=14, p2Points=15, score="Advantage player2"), - - dict(p1Points=6, p2Points=4, score="Win for player1"), - dict(p1Points=4, p2Points=6, score="Win for player2"), - dict(p1Points=16, p2Points=14, score="Win for player1"), - dict(p1Points=14, p2Points=16, score="Win for player2"), - ] - -def create_testcase_dicts(): - testcase_dicts = [] - for test in test_cases: - cleaned = test["score"] - cleaned = cleaned.replace("-", "") - cleaned = cleaned.replace(" ", "") - test["cleaned"] = cleaned - test["testcase_name"] = "%(cleaned)s_%(p1Points)s_%(p2Points)s" % test - testcase_dicts.append(test) - return testcase_dicts - -testcase_dicts = create_testcase_dicts() - -# This is not currently being used -gtest_template = """\ -TEST(TennisTest, %(testcase_name)s) { - EXPECT_EQ("%(score)s", tennis_score(%(p1Points)s, %(p2Points)s)); -} -""" - -template = """\ -void test_%(testcase_name)s() -{ - assert("%(score)s" == tennis_score(%(p1Points)s, %(p2Points)s)); -} -""" -# test cases for all_tests.cpp -for test in testcase_dicts: - print template % test - -# test_suite.tests.cpp -for test in testcase_dicts: - print " test_%(testcase_name)s," % test - -# all_tests.hpp -for test in testcase_dicts: - print "void test_%(testcase_name)s();" % test \ No newline at end of file diff --git a/Tennis/cpp/makefile b/Tennis/cpp/makefile deleted file mode 100644 index cfd4c776..00000000 --- a/Tennis/cpp/makefile +++ /dev/null @@ -1,5 +0,0 @@ -run.tests.output : run.tests - ./run.tests - -run.tests : *.cpp - g++ -Wall -Werror -O *.cpp -o run.tests \ No newline at end of file diff --git a/Tennis/cpp/tennis1.cc b/Tennis/cpp/tennis1.cc deleted file mode 100644 index 10ff0805..00000000 --- a/Tennis/cpp/tennis1.cc +++ /dev/null @@ -1,61 +0,0 @@ -#include - -const std::string tennis_score(int p1Score, int p2Score) { - std::string score = ""; - int tempScore=0; - if (p1Score==p2Score) - { - switch (p1Score) - { - case 0: - score = "Love-All"; - break; - case 1: - score = "Fifteen-All"; - break; - case 2: - score = "Thirty-All"; - break; - case 3: - score = "Deuce"; - break; - default: - score = "Deuce"; - break; - - } - } - else if (p1Score>=4 || p2Score>=4) - { - int minusResult = p1Score-p2Score; - if (minusResult==1) score ="Advantage player1"; - else if (minusResult ==-1) score ="Advantage player2"; - else if (minusResult>=2) score = "Win for player1"; - else score ="Win for player2"; - } - else - { - for (int i=1; i<3; i++) - { - if (i==1) tempScore = p1Score; - else { score+="-"; tempScore = p2Score;} - switch(tempScore) - { - case 0: - score+="Love"; - break; - case 1: - score+="Fifteen"; - break; - case 2: - score+="Thirty"; - break; - case 3: - score+="Forty"; - break; - } - } - } - return score; - -} diff --git a/Tennis/cpp/tennis2.cc b/Tennis/cpp/tennis2.cc deleted file mode 100644 index 3735dfeb..00000000 --- a/Tennis/cpp/tennis2.cc +++ /dev/null @@ -1,92 +0,0 @@ -#include - -const std::string tennis_score(int p1Score, int p2Score) { - std::string score = ""; - std::string P1res = ""; - std::string P2res = ""; - if (p1Score == p2Score && p1Score < 4) - { - if (p1Score==0) - score = "Love"; - if (p1Score==1) - score = "Fifteen"; - if (p1Score==2) - score = "Thirty"; - if (p1Score==3) - score = "Forty"; - score += "-All"; - } - if (p1Score==p2Score && p1Score>2) - score = "Deuce"; - - if (p1Score > 0 && p2Score==0) - { - if (p1Score==1) - P1res = "Fifteen"; - if (p1Score==2) - P1res = "Thirty"; - if (p1Score==3) - P1res = "Forty"; - - P2res = "Love"; - score = P1res + "-" + P2res; - } - if (p2Score > 0 && p1Score==0) - { - if (p2Score==1) - P2res = "Fifteen"; - if (p2Score==2) - P2res = "Thirty"; - if (p2Score==3) - P2res = "Forty"; - - P1res = "Love"; - score = P1res + "-" + P2res; - } - - if (p1Score>p2Score && p1Score < 4) - { - if (p1Score==2) - P1res="Thirty"; - if (p1Score==3) - P1res="Forty"; - if (p2Score==1) - P2res="Fifteen"; - if (p2Score==2) - P2res="Thirty"; - score = P1res + "-" + P2res; - } - if (p2Score>p1Score && p2Score < 4) - { - if (p2Score==2) - P2res="Thirty"; - if (p2Score==3) - P2res="Forty"; - if (p1Score==1) - P1res="Fifteen"; - if (p1Score==2) - P1res="Thirty"; - score = P1res + "-" + P2res; - } - - if (p1Score > p2Score && p2Score >= 3) - { - score = "Advantage player1"; - } - - if (p2Score > p1Score && p1Score >= 3) - { - score = "Advantage player2"; - } - - if (p1Score>=4 && p2Score>=0 && (p1Score-p2Score)>=2) - { - score = "Win for player1"; - } - if (p2Score>=4 && p1Score>=0 && (p2Score-p1Score)>=2) - { - score = "Win for player2"; - } - return score; - -} diff --git a/Tennis/cpp/tennis3.cc b/Tennis/cpp/tennis3.cc deleted file mode 100644 index cc87f969..00000000 --- a/Tennis/cpp/tennis3.cc +++ /dev/null @@ -1,17 +0,0 @@ -#include - -const std::string tennis_score(int p1, int p2) { - std::string s; - std::string p1N = "player1"; - std::string p2N = "player2"; - if (p1 < 4 && p2 < 4 && !(p1 == 3 && p2 == 3)) { - std::string p[4] = {"Love", "Fifteen", "Thirty", "Forty"}; - s = p[p1]; - return (p1 == p2) ? s + "-All" : s + "-" + p[p2]; - } else { - if (p1 == p2) - return "Deuce"; - s = p1 > p2 ? p1N : p2N; - return ((p1-p2)*(p1-p2) == 1) ? "Advantage " + s : "Win for " + s; - } -} \ No newline at end of file diff --git a/Tennis/cpp/test_suite.tests.cpp b/Tennis/cpp/test_suite.tests.cpp deleted file mode 100644 index cdadddfc..00000000 --- a/Tennis/cpp/test_suite.tests.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "all_tests.hpp" -#include -#include - -typedef void test(); - -static test * tests[ ] = -{ - test_LoveAll_0_0, - test_FifteenAll_1_1, - test_ThirtyAll_2_2, - test_Deuce_3_3, - test_Deuce_4_4, - test_FifteenLove_1_0, - test_LoveFifteen_0_1, - test_ThirtyLove_2_0, - test_LoveThirty_0_2, - test_FortyLove_3_0, - test_LoveForty_0_3, - test_Winforplayer1_4_0, - test_Winforplayer2_0_4, - test_ThirtyFifteen_2_1, - test_FifteenThirty_1_2, - test_FortyFifteen_3_1, - test_FifteenForty_1_3, - test_Winforplayer1_4_1, - test_Winforplayer2_1_4, - test_FortyThirty_3_2, - test_ThirtyForty_2_3, - test_Winforplayer1_4_2, - test_Winforplayer2_2_4, - test_Advantageplayer1_4_3, - test_Advantageplayer2_3_4, - test_Advantageplayer1_5_4, - test_Advantageplayer2_4_5, - test_Advantageplayer1_15_14, - test_Advantageplayer2_14_15, - test_Winforplayer1_6_4, - test_Winforplayer2_4_6, - test_Winforplayer1_16_14, - test_Winforplayer2_14_16, - static_cast(0), -}; - -int main() -{ - size_t at = 0; - while (tests[at]) - { - tests[at++](); - std::cout << '.'; - } - std::cout << std::endl << at << " tests passed" << std::endl; - return 0; -} diff --git a/Tennis/csharp/AssemblyInfo.cs b/Tennis/csharp/AssemblyInfo.cs deleted file mode 100644 index 115d92f5..00000000 --- a/Tennis/csharp/AssemblyInfo.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle("Tennis")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("emily")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion("1.0.*")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] - diff --git a/Tennis/csharp/Main.cs b/Tennis/csharp/Main.cs deleted file mode 100644 index 896d9de0..00000000 --- a/Tennis/csharp/Main.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace Tennis -{ - class MainClass - { - public static void Main (string[] args) - { - Console.WriteLine ("Hello World!"); - } - } -} diff --git a/Tennis/csharp/Tennis.csproj b/Tennis/csharp/Tennis.csproj deleted file mode 100644 index 34482ba2..00000000 --- a/Tennis/csharp/Tennis.csproj +++ /dev/null @@ -1,48 +0,0 @@ - - - - Debug - x86 - 9.0.21022 - 2.0 - {F059601E-EF1A-4148-A2A4-1E1697CC69EA} - Exe - Tennis - Tennis - v3.5 - - - True - full - False - bin\Debug - DEBUG; - prompt - 4 - x86 - True - - - none - True - bin\Release - prompt - 4 - x86 - True - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Tennis/csharp/TennisGame.cs b/Tennis/csharp/TennisGame.cs deleted file mode 100644 index 32f99a74..00000000 --- a/Tennis/csharp/TennisGame.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace Tennis -{ - public interface TennisGame - { - void WonPoint (string playerName); - string GetScore (); - - } -} - diff --git a/Tennis/csharp/TennisGame1.cs b/Tennis/csharp/TennisGame1.cs deleted file mode 100644 index 4412ccd4..00000000 --- a/Tennis/csharp/TennisGame1.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using NUnit.Framework; - -namespace Tennis -{ - class TennisGame1 : TennisGame - { - private int m_score1 = 0; - private int m_score2 = 0; - private string player1Name; - private string player2Name; - - public TennisGame1 (string player1Name, string player2Name) - { - this.player1Name = player1Name; - this.player2Name = player2Name; - } - - public void WonPoint (string playerName) - { - if (playerName == "player1") - m_score1 += 1; - else - m_score2 += 1; - } - - public string GetScore () - { - String score = ""; - int tempScore=0; - if (m_score1==m_score2) - { - switch (m_score1) - { - case 0: - score = "Love-All"; - break; - case 1: - score = "Fifteen-All"; - break; - case 2: - score = "Thirty-All"; - break; - case 3: - score = "Forty-All"; - break; - default: - score = "Deuce"; - break; - - } - } - else if (m_score1>=4 || m_score2>=4) - { - int minusResult = m_score1-m_score2; - if (minusResult==1) score ="Advantage player1"; - else if (minusResult ==-1) score ="Advantage player2"; - else if (minusResult>=2) score = "Win for player1"; - else score ="Win for player2"; - } - else - { - for (int i=1; i<3; i++) - { - if (i==1) tempScore = m_score1; - else { score+="-"; tempScore = m_score2;} - switch(tempScore) - { - case 0: - score+="Love"; - break; - case 1: - score+="Fifteen"; - break; - case 2: - score+="Thirty"; - break; - case 3: - score+="Forty"; - break; - } - } - } - return score; - } - } - -} - diff --git a/Tennis/csharp/TennisGame2.cs b/Tennis/csharp/TennisGame2.cs deleted file mode 100644 index d09b6c67..00000000 --- a/Tennis/csharp/TennisGame2.cs +++ /dev/null @@ -1,144 +0,0 @@ -using System; - -namespace Tennis -{ - public class TennisGame2 : TennisGame - { - public int P1point = 0; - public int P2point = 0; - - public string P1res = ""; - public string P2res = ""; - private string player1Name; - private string player2Name; - - public TennisGame2 (string player1Name, string player2Name) - { - this.player1Name = player1Name; - this.player2Name = player2Name; - } - - public string GetScore(){ - string score = ""; - if (P1point == P2point && P1point < 4) - { - if (P1point==0) - score = "Love"; - if (P1point==1) - score = "Fifteen"; - if (P1point==2) - score = "Thirty"; - if (P1point==3) - score = "Forty"; - score += "-All"; - } - if (P1point==P2point && P1point>3) - score = "Deuce"; - - if (P1point > 0 && P2point==0) - { - if (P1point==1) - P1res = "Fifteen"; - if (P1point==2) - P1res = "Thirty"; - if (P1point==3) - P1res = "Forty"; - - P2res = "Love"; - score = P1res + "-" + P2res; - } - if (P2point > 0 && P1point==0) - { - if (P2point==1) - P2res = "Fifteen"; - if (P2point==2) - P2res = "Thirty"; - if (P2point==3) - P2res = "Forty"; - - P1res = "Love"; - score = P1res + "-" + P2res; - } - - if (P1point>P2point && P1point < 4) - { - if (P1point==2) - P1res="Thirty"; - if (P1point==3) - P1res="Forty"; - if (P2point==1) - P2res="Fifteen"; - if (P2point==2) - P2res="Thirty"; - score = P1res + "-" + P2res; - } - if (P2point>P1point && P2point < 4) - { - if (P2point==2) - P2res="Thirty"; - if (P2point==3) - P2res="Forty"; - if (P1point==1) - P1res="Fifteen"; - if (P1point==2) - P1res="Thirty"; - score = P1res + "-" + P2res; - } - - if (P1point > P2point && P2point >= 3) - { - score = "Advantage player1"; - } - - if (P2point > P1point && P1point >= 3) - { - score = "Advantage player2"; - } - - if (P1point>=4 && P2point>=0 && (P1point-P2point)>=2) - { - score = "Win for player1"; - } - if (P2point>=4 && P1point>=0 && (P2point-P1point)>=2) - { - score = "Win for player2"; - } - return score; - } - - public void SetP1Score(int number){ - - for (int i = 0; i < number; i++) - { - P1Score(); - } - - } - - public void SetP2Score(int number){ - - for (int i = 0; i < number; i++) - { - P2Score(); - } - - } - - public void P1Score(){ - P1point++; - } - - public void P2Score(){ - P2point++; - } - - public void WonPoint(string player) { - if (player == "player1") - P1Score(); - else - P2Score(); - } - - } -} - diff --git a/Tennis/csharp/TennisGame3.cs b/Tennis/csharp/TennisGame3.cs deleted file mode 100644 index 1f3e9ba4..00000000 --- a/Tennis/csharp/TennisGame3.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; - -namespace Tennis -{ - public class TennisGame3 : TennisGame - { - private int p2; - private int p1; - private string p1N; - private string p2N; - - public TennisGame3 (string player1Name, string player2Name) - { - this.p1N = player1Name; - this.p2N = player2Name; - } - - public string GetScore() { - string s; - if (p1 < 4 && p2 < 4) { - string[] p = new String[]{"Love", "Fifteen", "Thirty", "Forty"}; - s = p[p1]; - return (p1 == p2) ? s + "-All" : s + "-" + p[p2]; - } else { - if (p1 == p2) - return "Deuce"; - s = p1 > p2 ? p1N : p2N; - return ((p1-p2)*(p1-p2) == 1) ? "Advantage " + s : "Win for " + s; - } - } - - public void WonPoint(string playerName) { - if (playerName == "player1") - this.p1 += 1; - else - this.p2 += 1; - } - - } -} - diff --git a/Tennis/csharp/TennisTest.cs b/Tennis/csharp/TennisTest.cs deleted file mode 100644 index bd2c4dd6..00000000 --- a/Tennis/csharp/TennisTest.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System; -using NUnit.Framework; - -namespace Tennis -{ - [TestFixture(0, 0, "Love-All")] - [TestFixture( 1, 1, "Fifteen-All" )] - [TestFixture( 2, 2, "Thirty-All")] - [TestFixture( 3, 3, "Forty-All")] - [TestFixture( 4, 4, "Deuce")] - [TestFixture( 1, 0, "Fifteen-Love")] - [TestFixture( 0, 1, "Love-Fifteen")] - [TestFixture( 2, 0, "Thirty-Love")] - [TestFixture( 0, 2, "Love-Thirty")] - [TestFixture( 3, 0, "Forty-Love")] - [TestFixture( 0, 3, "Love-Forty")] - [TestFixture( 4, 0, "Win for player1")] - [TestFixture( 0, 4, "Win for player2")] - [TestFixture( 2, 1, "Thirty-Fifteen")] - [TestFixture( 1, 2, "Fifteen-Thirty")] - [TestFixture( 3, 1, "Forty-Fifteen")] - [TestFixture( 1, 3, "Fifteen-Forty")] - [TestFixture( 4, 1, "Win for player1")] - [TestFixture( 1, 4, "Win for player2")] - [TestFixture( 3, 2, "Forty-Thirty")] - [TestFixture( 2, 3, "Thirty-Forty")] - [TestFixture( 4, 2, "Win for player1")] - [TestFixture( 2, 4, "Win for player2")] - [TestFixture( 4, 3, "Advantage player1")] - [TestFixture( 3, 4, "Advantage player2")] - [TestFixture( 5, 4, "Advantage player1")] - [TestFixture( 4, 5, "Advantage player2")] - [TestFixture( 15, 14, "Advantage player1")] - [TestFixture( 14, 15, "Advantage player2")] - [TestFixture( 6, 4, "Win for player1")] - [TestFixture( 4, 6, "Win for player2")] - [TestFixture( 16, 14, "Win for player1")] - [TestFixture( 14, 16, "Win for player2")] - public class TennisTest - { - private int player1Score; - private int player2Score; - private string expectedScore; - - public TennisTest(int player1Score, int player2Score, string expectedScore) { - this.player1Score = player1Score; - this.player2Score = player2Score; - this.expectedScore = expectedScore; - } - - [Test] - public void checkTennisGame1() { - TennisGame1 game = new TennisGame1("player1", "player2"); - checkAllScores(game); - } - - [Test] - public void checkTennisGame2() { - TennisGame2 game = new TennisGame2("player1", "player2"); - checkAllScores(game); - } - - [Test] - public void checkTennisGame3() { - TennisGame3 game = new TennisGame3("player1", "player2"); - checkAllScores(game); - } - - public void checkAllScores(TennisGame game) { - int highestScore = Math.Max(this.player1Score, this.player2Score); - for (int i = 0; i < highestScore; i++) { - if (i < this.player1Score) - game.WonPoint("player1"); - if (i < this.player2Score) - game.WonPoint("player2"); - } - Assert.AreEqual(this.expectedScore, game.GetScore()); - } - - } - - [TestFixture()] - public class ExampleGameTennisTest - { - public void RealisticTennisGame(TennisGame game) - { - String[] points = {"player1", "player1", "player2", "player2", "player1", "player1"}; - String[] expected_scores = {"Fifteen-Love", "Thirty-Love", "Thirty-Fifteen", "Thirty-All", "Forty-Thirty", "Win for player1"}; - for (int i = 0; i < 6; i++) { - game.WonPoint(points[i]); - Assert.AreEqual(expected_scores[i], game.GetScore()); - } - } - [Test()] - public void CheckGame1() - { - TennisGame1 game = new TennisGame1("player1", "player2"); - RealisticTennisGame(game); - } - [Test()] - public void CheckGame2() - { - TennisGame2 game = new TennisGame2("player1", "player2"); - RealisticTennisGame(game); - } - [Test()] - public void CheckGame3() - { - TennisGame3 game = new TennisGame3("player1", "player2"); - RealisticTennisGame(game); - } - } - -} - diff --git a/Tennis/java/TennisGame.java b/Tennis/java/TennisGame.java deleted file mode 100644 index 330f3f45..00000000 --- a/Tennis/java/TennisGame.java +++ /dev/null @@ -1,5 +0,0 @@ - -public interface TennisGame { - void wonPoint(String playerName); - String getScore(); -} \ No newline at end of file diff --git a/Tennis/java/TennisGame1.java b/Tennis/java/TennisGame1.java deleted file mode 100644 index c92d5fab..00000000 --- a/Tennis/java/TennisGame1.java +++ /dev/null @@ -1,79 +0,0 @@ - -public class TennisGame1 implements TennisGame { - - private int m_score1 = 0; - private int m_score2 = 0; - private String player1Name; - private String player2Name; - - public TennisGame1(String player1Name, String player2Name) { - this.player1Name = player1Name; - this.player2Name = player2Name; - } - - public void wonPoint(String playerName) { - if (playerName == "player1") - m_score1 += 1; - else - m_score2 += 1; - } - - public String getScore() { - String score = ""; - int tempScore=0; - if (m_score1==m_score2) - { - switch (m_score1) - { - case 0: - score = "Love-All"; - break; - case 1: - score = "Fifteen-All"; - break; - case 2: - score = "Thirty-All"; - break; - case 3: - score = "Forty-All"; - break; - default: - score = "Deuce"; - break; - - } - } - else if (m_score1>=4 || m_score2>=4) - { - int minusResult = m_score1-m_score2; - if (minusResult==1) score ="Advantage player1"; - else if (minusResult ==-1) score ="Advantage player2"; - else if (minusResult>=2) score = "Win for player1"; - else score ="Win for player2"; - } - else - { - for (int i=1; i<3; i++) - { - if (i==1) tempScore = m_score1; - else { score+="-"; tempScore = m_score2;} - switch(tempScore) - { - case 0: - score+="Love"; - break; - case 1: - score+="Fifteen"; - break; - case 2: - score+="Thirty"; - break; - case 3: - score+="Forty"; - break; - } - } - } - return score; - } -} diff --git a/Tennis/java/TennisGame2.java b/Tennis/java/TennisGame2.java deleted file mode 100644 index 461d57df..00000000 --- a/Tennis/java/TennisGame2.java +++ /dev/null @@ -1,137 +0,0 @@ - -public class TennisGame2 implements TennisGame -{ - public int P1point = 0; - public int P2point = 0; - - public String P1res = ""; - public String P2res = ""; - private String player1Name; - private String player2Name; - - public TennisGame2(String player1Name, String player2Name) { - this.player1Name = player1Name; - this.player2Name = player2Name; - } - - public String getScore(){ - String score = ""; - if (P1point == P2point && P1point < 4) - { - if (P1point==0) - score = "Love"; - if (P1point==1) - score = "Fifteen"; - if (P1point==2) - score = "Thirty"; - if (P1point==3) - score = "Forty"; - score += "-All"; - } - if (P1point==P2point && P1point>3) - score = "Deuce"; - - if (P1point > 0 && P2point==0) - { - if (P1point==1) - P1res = "Fifteen"; - if (P1point==2) - P1res = "Thirty"; - if (P1point==3) - P1res = "Forty"; - - P2res = "Love"; - score = P1res + "-" + P2res; - } - if (P2point > 0 && P1point==0) - { - if (P2point==1) - P2res = "Fifteen"; - if (P2point==2) - P2res = "Thirty"; - if (P2point==3) - P2res = "Forty"; - - P1res = "Love"; - score = P1res + "-" + P2res; - } - - if (P1point>P2point && P1point < 4) - { - if (P1point==2) - P1res="Thirty"; - if (P1point==3) - P1res="Forty"; - if (P2point==1) - P2res="Fifteen"; - if (P2point==2) - P2res="Thirty"; - score = P1res + "-" + P2res; - } - if (P2point>P1point && P2point < 4) - { - if (P2point==2) - P2res="Thirty"; - if (P2point==3) - P2res="Forty"; - if (P1point==1) - P1res="Fifteen"; - if (P1point==2) - P1res="Thirty"; - score = P1res + "-" + P2res; - } - - if (P1point > P2point && P2point >= 3) - { - score = "Advantage player1"; - } - - if (P2point > P1point && P1point >= 3) - { - score = "Advantage player2"; - } - - if (P1point>=4 && P2point>=0 && (P1point-P2point)>=2) - { - score = "Win for player1"; - } - if (P2point>=4 && P1point>=0 && (P2point-P1point)>=2) - { - score = "Win for player2"; - } - return score; - } - - public void SetP1Score(int number){ - - for (int i = 0; i < number; i++) - { - P1Score(); - } - - } - - public void SetP2Score(int number){ - - for (int i = 0; i < number; i++) - { - P2Score(); - } - - } - - public void P1Score(){ - P1point++; - } - - public void P2Score(){ - P2point++; - } - - public void wonPoint(String player) { - if (player == "player1") - P1Score(); - else - P2Score(); - } -} \ No newline at end of file diff --git a/Tennis/java/TennisGame3.java b/Tennis/java/TennisGame3.java deleted file mode 100644 index f222b460..00000000 --- a/Tennis/java/TennisGame3.java +++ /dev/null @@ -1,36 +0,0 @@ - -public class TennisGame3 implements TennisGame { - - private int p2; - private int p1; - private String p1N; - private String p2N; - - public TennisGame3(String p1N, String p2N) { - this.p1N = p1N; - this.p2N = p2N; - } - - public String getScore() { - String s; - if (p1 < 4 && p2 < 4) { - String[] p = new String[]{"Love", "Fifteen", "Thirty", "Forty"}; - s = p[p1]; - return (p1 == p2) ? s + "-All" : s + "-" + p[p2]; - } else { - if (p1 == p2) - return "Deuce"; - s = p1 > p2 ? p1N : p2N; - return ((p1-p2)*(p1-p2) == 1) ? "Advantage " + s : "Win for " + s; - } - } - - public void wonPoint(String playerName) { - if (playerName == "player1") - this.p1 += 1; - else - this.p2 += 1; - - } - -} diff --git a/Tennis/java/TennisTest.java b/Tennis/java/TennisTest.java deleted file mode 100644 index c03990ca..00000000 --- a/Tennis/java/TennisTest.java +++ /dev/null @@ -1,98 +0,0 @@ -import static org.junit.Assert.*; - -import java.util.Arrays; -import java.util.Collection; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -@RunWith(Parameterized.class) -public class TennisTest { - - private int player1Score; - private int player2Score; - private String expectedScore; - - public TennisTest(int player1Score, int player2Score, String expectedScore) { - this.player1Score = player1Score; - this.player2Score = player2Score; - this.expectedScore = expectedScore; - } - - @Parameters - public static Collection getAllScores() { - return Arrays.asList(new Object[][] { - { 0, 0, "Love-All" }, - { 1, 1, "Fifteen-All" }, - { 2, 2, "Thirty-All"}, - { 3, 3, "Forty-All"}, - { 4, 4, "Deuce"}, - - { 1, 0, "Fifteen-Love"}, - { 0, 1, "Love-Fifteen"}, - { 2, 0, "Thirty-Love"}, - { 0, 2, "Love-Thirty"}, - { 3, 0, "Forty-Love"}, - { 0, 3, "Love-Forty"}, - { 4, 0, "Win for player1"}, - { 0, 4, "Win for player2"}, - - { 2, 1, "Thirty-Fifteen"}, - { 1, 2, "Fifteen-Thirty"}, - { 3, 1, "Forty-Fifteen"}, - { 1, 3, "Fifteen-Forty"}, - { 4, 1, "Win for player1"}, - { 1, 4, "Win for player2"}, - - { 3, 2, "Forty-Thirty"}, - { 2, 3, "Thirty-Forty"}, - { 4, 2, "Win for player1"}, - { 2, 4, "Win for player2"}, - - { 4, 3, "Advantage player1"}, - { 3, 4, "Advantage player2"}, - { 5, 4, "Advantage player1"}, - { 4, 5, "Advantage player2"}, - { 15, 14, "Advantage player1"}, - { 14, 15, "Advantage player2"}, - - { 6, 4, "Win for player1"}, - { 4, 6, "Win for player2"}, - { 16, 14, "Win for player1"}, - { 14, 16, "Win for player2"}, - }); - } - - public void checkAllScores(TennisGame game) { - int highestScore = Math.max(this.player1Score, this.player2Score); - for (int i = 0; i < highestScore; i++) { - if (i < this.player1Score) - game.wonPoint("player1"); - if (i < this.player2Score) - game.wonPoint("player2"); - } - assertEquals(this.expectedScore, game.getScore()); - } - - @Test - public void checkAllScoresTennisGame1() { - TennisGame1 game = new TennisGame1("player1", "player2"); - checkAllScores(game); - } - - @Test - public void checkAllScoresTennisGame2() { - TennisGame2 game = new TennisGame2("player1", "player2"); - checkAllScores(game); - } - - @Test - public void checkAllScoresTennisGame3() { - TennisGame3 game = new TennisGame3("player1", "player2"); - checkAllScores(game); - } - -} diff --git a/Tennis/objc/.gitignore b/Tennis/objc/.gitignore deleted file mode 100644 index 732b3824..00000000 --- a/Tennis/objc/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.idea -Tennis.xcodeproj/project.xcworkspace/xcuserdata/* -Tennis.xcodeproj/xcuserdata/* diff --git a/Tennis/objc/Tennis.xcodeproj/project.pbxproj b/Tennis/objc/Tennis.xcodeproj/project.pbxproj deleted file mode 100644 index a834059a..00000000 --- a/Tennis/objc/Tennis.xcodeproj/project.pbxproj +++ /dev/null @@ -1,305 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - CACF63F14142F5803F786695 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CACF69F4ABB8AC23884C74C3 /* Foundation.framework */; }; - CACF6414A388566B43A9BCB5 /* TennisGame.m in Sources */ = {isa = PBXBuildFile; fileRef = CACF649AAFA398A61A600CB7 /* TennisGame.m */; }; - CACF66A873EB3C4C2A1B7D78 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CACF6C52F7301D6A288FECCA /* UIKit.framework */; }; - CACF6871FE27A26189B71C29 /* TennisGame1.m in Sources */ = {isa = PBXBuildFile; fileRef = CACF6BF242B4F5F91193BEC7 /* TennisGame1.m */; }; - CACF68FFD67D0173EDF11BF4 /* TennisTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CACF6D897D4F49BCD1B41947 /* TennisTests.m */; }; - CACF6C5876E4687F7A65AF54 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CACF6A13AA71A254E309FB03 /* SenTestingKit.framework */; }; - CACF6E1993921B2EC1995F0E /* TennisGame2.m in Sources */ = {isa = PBXBuildFile; fileRef = CACF64EDAB086A5F18E393EE /* TennisGame2.m */; }; - CACF6F3B5CEDAF9DFE1B8A64 /* TennisGame3.m in Sources */ = {isa = PBXBuildFile; fileRef = CACF6BAD45E82D978466F92B /* TennisGame3.m */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - CACF61291A7012C7769FCE61 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; - CACF6419833B61F7E3D89075 /* TennisGame3.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TennisGame3.h; sourceTree = ""; }; - CACF649AAFA398A61A600CB7 /* TennisGame.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TennisGame.m; sourceTree = ""; }; - CACF64EDAB086A5F18E393EE /* TennisGame2.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TennisGame2.m; sourceTree = ""; }; - CACF665E8EA24EE215E5498C /* TennisTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TennisTests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; - CACF6771858FAF6F6F4650A6 /* TennisGame2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TennisGame2.h; sourceTree = ""; }; - CACF69F4ABB8AC23884C74C3 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; - CACF6A13AA71A254E309FB03 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; }; - CACF6A4205D54CCF3AEA2B65 /* TennisTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TennisTests.h; sourceTree = ""; }; - CACF6A964A59A72222255B2C /* TennisGame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TennisGame.h; sourceTree = ""; }; - CACF6B7F36643E0787BABC39 /* TennisGame1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TennisGame1.h; sourceTree = ""; }; - CACF6BAD45E82D978466F92B /* TennisGame3.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TennisGame3.m; sourceTree = ""; }; - CACF6BF242B4F5F91193BEC7 /* TennisGame1.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TennisGame1.m; sourceTree = ""; }; - CACF6C52F7301D6A288FECCA /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; - CACF6D897D4F49BCD1B41947 /* TennisTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TennisTests.m; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - CACF6A7D79290F13325B461F /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - CACF6C5876E4687F7A65AF54 /* SenTestingKit.framework in Frameworks */, - CACF66A873EB3C4C2A1B7D78 /* UIKit.framework in Frameworks */, - CACF63F14142F5803F786695 /* Foundation.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - CACF60033C37E3B5C11CC734 /* Frameworks */ = { - isa = PBXGroup; - children = ( - CACF6C52F7301D6A288FECCA /* UIKit.framework */, - CACF69F4ABB8AC23884C74C3 /* Foundation.framework */, - CACF61291A7012C7769FCE61 /* CoreGraphics.framework */, - CACF6A13AA71A254E309FB03 /* SenTestingKit.framework */, - ); - name = Frameworks; - sourceTree = ""; - }; - CACF652B01231CADE96100D1 = { - isa = PBXGroup; - children = ( - CACF67CF0393B97F4DC41E0B /* Tennis */, - CACF65D28A08CBB9A2C540F5 /* TennisTests */, - CACF6E7D48293F4D43E7A6DC /* Products */, - CACF60033C37E3B5C11CC734 /* Frameworks */, - ); - sourceTree = ""; - }; - CACF65D28A08CBB9A2C540F5 /* TennisTests */ = { - isa = PBXGroup; - children = ( - CACF6A4205D54CCF3AEA2B65 /* TennisTests.h */, - CACF6D897D4F49BCD1B41947 /* TennisTests.m */, - ); - path = TennisTests; - sourceTree = ""; - }; - CACF67CF0393B97F4DC41E0B /* Tennis */ = { - isa = PBXGroup; - children = ( - CACF6BF242B4F5F91193BEC7 /* TennisGame1.m */, - CACF6B7F36643E0787BABC39 /* TennisGame1.h */, - CACF64EDAB086A5F18E393EE /* TennisGame2.m */, - CACF6771858FAF6F6F4650A6 /* TennisGame2.h */, - CACF6BAD45E82D978466F92B /* TennisGame3.m */, - CACF6419833B61F7E3D89075 /* TennisGame3.h */, - CACF649AAFA398A61A600CB7 /* TennisGame.m */, - CACF6A964A59A72222255B2C /* TennisGame.h */, - ); - path = Tennis; - sourceTree = ""; - }; - CACF6E7D48293F4D43E7A6DC /* Products */ = { - isa = PBXGroup; - children = ( - CACF665E8EA24EE215E5498C /* TennisTests.octest */, - ); - name = Products; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - CACF6DE0B90C4D92A2B3D5E6 /* TennisTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = CACF68FD0CC2343E15B3AA80 /* Build configuration list for PBXNativeTarget "TennisTests" */; - buildPhases = ( - CACF6FE60766CDED5F49C391 /* Sources */, - CACF6A7D79290F13325B461F /* Frameworks */, - CACF6814909F4B826FA2E0CA /* Resources */, - CACF6F4E118C6D42BF7A89A2 /* ShellScript */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = TennisTests; - productName = TennisTests; - productReference = CACF665E8EA24EE215E5498C /* TennisTests.octest */; - productType = "com.apple.product-type.bundle"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - CACF6DA3161729BC17499E03 /* Project object */ = { - isa = PBXProject; - attributes = { - ORGANIZATIONNAME = "Stefan van den Oord"; - }; - buildConfigurationList = CACF6959B8F6F7EC1647AAB0 /* Build configuration list for PBXProject "Tennis" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = CACF652B01231CADE96100D1; - productRefGroup = CACF6E7D48293F4D43E7A6DC /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - CACF6DE0B90C4D92A2B3D5E6 /* TennisTests */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - CACF6814909F4B826FA2E0CA /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXShellScriptBuildPhase section */ - CACF6F4E118C6D42BF7A89A2 /* ShellScript */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n"; - }; -/* End PBXShellScriptBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - CACF6FE60766CDED5F49C391 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - CACF68FFD67D0173EDF11BF4 /* TennisTests.m in Sources */, - CACF6F3B5CEDAF9DFE1B8A64 /* TennisGame3.m in Sources */, - CACF6E1993921B2EC1995F0E /* TennisGame2.m in Sources */, - CACF6871FE27A26189B71C29 /* TennisGame1.m in Sources */, - CACF6414A388566B43A9BCB5 /* TennisGame.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - CACF601C65BCC0FBE3D880E3 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - BUNDLE_LOADER = ""; - FRAMEWORK_SEARCH_PATHS = ( - "\"$(SDKROOT)/Developer/Library/Frameworks\"", - "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"", - ); - GCC_PRECOMPILE_PREFIX_HEADER = YES; - PRODUCT_NAME = "$(TARGET_NAME)"; - TEST_HOST = ""; - WRAPPER_EXTENSION = octest; - }; - name = Release; - }; - CACF6452D3F349731DB85BE9 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 6.1; - OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; - SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2"; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; - CACF6A641D1372E5C5478EB2 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - BUNDLE_LOADER = ""; - FRAMEWORK_SEARCH_PATHS = ( - "\"$(SDKROOT)/Developer/Library/Frameworks\"", - "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"", - ); - GCC_PRECOMPILE_PREFIX_HEADER = YES; - PRODUCT_NAME = "$(TARGET_NAME)"; - TEST_HOST = ""; - WRAPPER_EXTENSION = octest; - }; - name = Debug; - }; - CACF6FD238549A86B0925D65 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 6.1; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - CACF68FD0CC2343E15B3AA80 /* Build configuration list for PBXNativeTarget "TennisTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - CACF601C65BCC0FBE3D880E3 /* Release */, - CACF6A641D1372E5C5478EB2 /* Debug */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - CACF6959B8F6F7EC1647AAB0 /* Build configuration list for PBXProject "Tennis" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - CACF6452D3F349731DB85BE9 /* Release */, - CACF6FD238549A86B0925D65 /* Debug */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = CACF6DA3161729BC17499E03 /* Project object */; -} diff --git a/Tennis/objc/Tennis.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Tennis/objc/Tennis.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 62edb4d0..00000000 --- a/Tennis/objc/Tennis.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/Tennis/objc/Tennis.xcodeproj/xcshareddata/xcschemes/TennisTests.xcscheme b/Tennis/objc/Tennis.xcodeproj/xcshareddata/xcschemes/TennisTests.xcscheme deleted file mode 100644 index b42dc928..00000000 --- a/Tennis/objc/Tennis.xcodeproj/xcshareddata/xcschemes/TennisTests.xcscheme +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tennis/objc/Tennis/TennisGame.h b/Tennis/objc/Tennis/TennisGame.h deleted file mode 100644 index 613d95b4..00000000 --- a/Tennis/objc/Tennis/TennisGame.h +++ /dev/null @@ -1,9 +0,0 @@ -#import - -@interface TennisGame : NSObject - -- (id)initWithPlayer1:(NSString *)player1 player2:(NSString *)player2; -- (void)wonPoint:(NSString *)playerName; -- (NSString *)score; - -@end \ No newline at end of file diff --git a/Tennis/objc/Tennis/TennisGame.m b/Tennis/objc/Tennis/TennisGame.m deleted file mode 100644 index 7462ad08..00000000 --- a/Tennis/objc/Tennis/TennisGame.m +++ /dev/null @@ -1,10 +0,0 @@ - -#import "TennisGame.h" - -@implementation TennisGame - -- (id)initWithPlayer1:(NSString *)player1 player2:(NSString *)player2 { return [super init]; } -- (void)wonPoint:(NSString *)playerName {} -- (NSString *)score { return nil; } - -@end \ No newline at end of file diff --git a/Tennis/objc/Tennis/TennisGame1.h b/Tennis/objc/Tennis/TennisGame1.h deleted file mode 100644 index 87db1ac7..00000000 --- a/Tennis/objc/Tennis/TennisGame1.h +++ /dev/null @@ -1,5 +0,0 @@ -#import -#import "TennisGame.h" - -@interface TennisGame1 : TennisGame -@end \ No newline at end of file diff --git a/Tennis/objc/Tennis/TennisGame1.m b/Tennis/objc/Tennis/TennisGame1.m deleted file mode 100644 index 99aee340..00000000 --- a/Tennis/objc/Tennis/TennisGame1.m +++ /dev/null @@ -1,92 +0,0 @@ -#import "TennisGame1.h" - -@interface TennisGame1 () -@property(nonatomic, copy) NSString *player1; -@property(nonatomic, copy) NSString *player2; -@end - -@implementation TennisGame1 { - int score1; - int score2; -} - -- (id)initWithPlayer1:(NSString *)player1 player2:(NSString *)player2 { - self = [super init]; - if (self) { - self.player1 = player1; - self.player2 = player2; - score1 = 0; - score2 = 0; - } - - return self; -} - -- (void)wonPoint:(NSString *)playerName { - if ([playerName isEqualToString:@"player1"]) - score1 += 1; - else - score2 += 1; -} - -- (NSString *)score { - NSString *score = @""; - int tempScore=0; - if (score1 == score2) - { - switch (score1) - { - case 0: - score = @"Love-All"; - break; - case 1: - score = @"Fifteen-All"; - break; - case 2: - score = @"Thirty-All"; - break; - case 3: - score = @"Forty-All"; - break; - default: - score = @"Deuce"; - break; - - } - } - else if (score1>=4 || score2>=4) - { - int minusResult = score1-score2; - if (minusResult==1) score = @"Advantage player1"; - else if (minusResult ==-1) score = @"Advantage player2"; - else if (minusResult>=2) score = @"Win for player1"; - else score = @"Win for player2"; - } - else - { - for (int i=1; i<3; i++) - { - if (i==1) tempScore = score1; - else { score = [NSString stringWithFormat:@"%@-", score]; tempScore = score2; } - switch(tempScore) - { - case 0: - score = [NSString stringWithFormat:@"%@Love", score]; - break; - case 1: - score = [NSString stringWithFormat:@"%@Fifteen", score]; - break; - case 2: - score = [NSString stringWithFormat:@"%@Thirty", score]; - break; - case 3: - score = [NSString stringWithFormat:@"%@Forty", score]; - break; - } - } - } - return score; -} - - -@end \ No newline at end of file diff --git a/Tennis/objc/Tennis/TennisGame2.h b/Tennis/objc/Tennis/TennisGame2.h deleted file mode 100644 index 4b899985..00000000 --- a/Tennis/objc/Tennis/TennisGame2.h +++ /dev/null @@ -1,5 +0,0 @@ -#import -#import "TennisGame.h" - -@interface TennisGame2 : TennisGame -@end \ No newline at end of file diff --git a/Tennis/objc/Tennis/TennisGame2.m b/Tennis/objc/Tennis/TennisGame2.m deleted file mode 100644 index c7ea3310..00000000 --- a/Tennis/objc/Tennis/TennisGame2.m +++ /dev/null @@ -1,147 +0,0 @@ -#import "TennisGame2.h" - -@interface TennisGame2 () -@property(nonatomic, copy) NSString *player2Name; -@property(nonatomic, copy) NSString *player1Name; -@end - -@implementation TennisGame2 { - int P1point; - NSString *P1res; - int P2point; - NSString *P2res; -} - -- (id)initWithPlayer1:(NSString *)player1Name player2:(NSString *)player2Name { - self = [super initWithPlayer1:player1Name player2:player2Name]; - if (self) { - self.player1Name = player1Name; - self.player2Name = player2Name; - } - - return self; -} - - -- (NSString *)score { - NSString *score = @""; - if (P1point == P2point && P1point < 4) - { - if (P1point==0) - score = @"Love"; - if (P1point==1) - score = @"Fifteen"; - if (P1point==2) - score = @"Thirty"; - if (P1point==3) - score = @"Forty"; - score = [NSString stringWithFormat:@"%@-All", score]; - } - if (P1point==P2point && P1point>3) - score = @"Deuce"; - - if (P1point > 0 && P2point==0) - { - if (P1point==1) - P1res = @"Fifteen"; - if (P1point==2) - P1res = @"Thirty"; - if (P1point==3) - P1res = @"Forty"; - - P2res = @"Love"; - score = [NSString stringWithFormat:@"%@-%@", P1res, P2res]; - } - if (P2point > 0 && P1point==0) - { - if (P2point==1) - P2res = @"Fifteen"; - if (P2point==2) - P2res = @"Thirty"; - if (P2point==3) - P2res = @"Forty"; - - P1res = @"Love"; - score = [NSString stringWithFormat:@"%@-%@", P1res, P2res]; - } - - if (P1point>P2point && P1point < 4) - { - if (P1point==2) - P1res=@"Thirty"; - if (P1point==3) - P1res=@"Forty"; - if (P2point==1) - P2res=@"Fifteen"; - if (P2point==2) - P2res=@"Thirty"; - score = [NSString stringWithFormat:@"%@-%@", P1res, P2res]; - } - if (P2point>P1point && P2point < 4) - { - if (P2point==2) - P2res=@"Thirty"; - if (P2point==3) - P2res=@"Forty"; - if (P1point==1) - P1res=@"Fifteen"; - if (P1point==2) - P1res=@"Thirty"; - score = [NSString stringWithFormat:@"%@-%@", P1res, P2res]; - } - - if (P1point > P2point && P2point >= 3) - { - score = @"Advantage player1"; - } - - if (P2point > P1point && P1point >= 3) - { - score = @"Advantage player2"; - } - - if (P1point>=4 && P2point>=0 && (P1point-P2point)>=2) - { - score = @"Win for player1"; - } - if (P2point>=4 && P1point>=0 && (P2point-P1point)>=2) - { - score = @"Win for player2"; - } - return score; -} - --(void)setP1Score:(int)number { - - for (int i = 0; i < number; i++) - { - [self P1Score]; - } - -} - -- (void)setP2Score:(int)number { - - for (int i = 0; i < number; i++) - { - [self P2Score]; - } - -} - -- (void)P1Score { - P1point++; -} - -- (void)P2Score { - P2point++; -} - -- (void)wonPoint:(NSString *)playerName { - if ([playerName isEqualToString:@"player1"]) - [self P1Score]; - else - [self P2Score]; -} - -@end \ No newline at end of file diff --git a/Tennis/objc/Tennis/TennisGame3.h b/Tennis/objc/Tennis/TennisGame3.h deleted file mode 100644 index 99b4b06d..00000000 --- a/Tennis/objc/Tennis/TennisGame3.h +++ /dev/null @@ -1,5 +0,0 @@ -#import -#import "TennisGame.h" - -@interface TennisGame3 : TennisGame -@end \ No newline at end of file diff --git a/Tennis/objc/Tennis/TennisGame3.m b/Tennis/objc/Tennis/TennisGame3.m deleted file mode 100644 index d1e67697..00000000 --- a/Tennis/objc/Tennis/TennisGame3.m +++ /dev/null @@ -1,46 +0,0 @@ -#import "TennisGame3.h" - -@interface TennisGame3 () -@end - -@implementation TennisGame3 { - int p1; - int p2; - NSString *p1N; - NSString *p2N; -} - -- (id)initWithPlayer1:(NSString *)ap1N player2:(NSString *)ap2N { - self = [super initWithPlayer1:ap1N player2:ap2N]; - if (self) { - p1N = ap1N; - p2N = ap2N; - p1 = 0; - p2 = 0; - } - return self; -} - -- (NSString *)score { - NSString *s; - if (p1 < 4 && p2 < 4) { - NSArray* p = @[@"Love", @"Fifteen", @"Thirty", @"Forty"]; - s = p[p1]; - return (p1 == p2) ? [NSString stringWithFormat:@"%@-All",s] : [NSString stringWithFormat:@"%@-%@",s,p[p2]]; - } else { - if (p1 == p2) - return @"Deuce"; - s = p1 > p2 ? p1N : p2N; - return ((p1-p2)*(p1-p2) == 1) ? [NSString stringWithFormat:@"Advantage %@",s] : [NSString stringWithFormat:@"Win for %@",s]; - } -} - -- (void)wonPoint:(NSString *)playerName { - if ([playerName isEqualToString:@"player1"]) - p1 += 1; - else - p2 += 1; -} - - -@end \ No newline at end of file diff --git a/Tennis/objc/TennisTests/TennisTests.h b/Tennis/objc/TennisTests/TennisTests.h deleted file mode 100644 index dcc027a0..00000000 --- a/Tennis/objc/TennisTests/TennisTests.h +++ /dev/null @@ -1,5 +0,0 @@ -#import - -@interface TennisTests : SenTestCase -- (id)initWithInvocation:(NSInvocation *)invocation scores:(NSArray *)scores; -@end diff --git a/Tennis/objc/TennisTests/TennisTests.m b/Tennis/objc/TennisTests/TennisTests.m deleted file mode 100644 index 9fcc6101..00000000 --- a/Tennis/objc/TennisTests/TennisTests.m +++ /dev/null @@ -1,121 +0,0 @@ -#import -#import "TennisTests.h" -#import "TennisGame1.h" -#import "TennisGame2.h" -#import "TennisGame3.h" - -@interface TennisTests() -+ (NSArray*)parameters; -@end - -@implementation TennisTests (Parametrized) -+ (id)defaultTestSuite { - SenTestSuite *testSuite = [[SenTestSuite alloc] initWithName:NSStringFromClass(self)]; - - NSArray *allScores = [self parameters]; - for (NSArray *scores in allScores) { - [self addTestWithScores:scores toTestSuite:testSuite]; - } - - return testSuite; -} -+ (void)addTestWithScores:(NSArray *)scores toTestSuite:(SenTestSuite *)testSuite { - NSArray *testInvocations = [self testInvocations]; - for (NSInvocation *testInvocation in testInvocations) { - SenTestCase *test = [[TennisTests alloc] initWithInvocation:testInvocation scores:scores]; - [testSuite addTest:test]; - } -} -@end - -@implementation TennisTests { - int player1Score; - int player2Score; - NSString *expectedScore; -} - -+ (NSArray*)parameters { - return @[ - @[ @0, @0, @"Love-All"], - @[ @1, @1, @"Fifteen-All"], - @[ @2, @2, @"Thirty-All"], - @[ @3, @3, @"Forty-All"], - @[ @4, @4, @"Deuce"], - - @[ @1, @0, @"Fifteen-Love"], - @[ @0, @1, @"Love-Fifteen"], - @[ @2, @0, @"Thirty-Love"], - @[ @0, @2, @"Love-Thirty"], - @[ @3, @0, @"Forty-Love"], - @[ @0, @3, @"Love-Forty"], - @[ @4, @0, @"Win for player1"], - @[ @0, @4, @"Win for player2"], - - @[ @2, @1, @"Thirty-Fifteen"], - @[ @1, @2, @"Fifteen-Thirty"], - @[ @3, @1, @"Forty-Fifteen"], - @[ @1, @3, @"Fifteen-Forty"], - @[ @4, @1, @"Win for player1"], - @[ @1, @4, @"Win for player2"], - - @[ @3, @2, @"Forty-Thirty"], - @[ @2, @3, @"Thirty-Forty"], - @[ @4, @2, @"Win for player1"], - @[ @2, @4, @"Win for player2"], - - @[ @4, @3, @"Advantage player1"], - @[ @3, @4, @"Advantage player2"], - @[ @5, @4, @"Advantage player1"], - @[ @4, @5, @"Advantage player2"], - @[ @15, @14, @"Advantage player1"], - @[ @14, @15, @"Advantage player2"], - - @[ @6, @4, @"Win for player1"], - @[ @4, @6, @"Win for player2"], - @[ @16, @14, @"Win for player1"], - @[ @14, @16, @"Win for player2"] - ]; -} - -- (id)initWithInvocation:(NSInvocation *)invocation scores:(NSArray *)scores { - self = [super initWithInvocation:invocation]; - if (self) { - player1Score = [scores[0] intValue]; - player2Score = [scores[1] intValue]; - expectedScore = scores[2]; - } - return self; -} - -- (NSString *)name { - NSString *parametersDescription = [NSString stringWithFormat:@" (%d,%d,%@)]", player1Score, player2Score, expectedScore]; - return [[super name] stringByReplacingOccurrencesOfString:@"]" withString:parametersDescription]; -} - -- (void)checkAllScoresForGame:(TennisGame *)game { - int highestScore = MAX(player1Score, player2Score); - for (int i = 0; i < highestScore; i++) { - if (i < player1Score) - [game wonPoint:@"player1"]; - if (i < player2Score) - [game wonPoint:@"player2"]; - } - STAssertEqualObjects([game score], expectedScore, @""); -} - -- (void)testAllScoresTennisGame1 { - TennisGame1 * game = [[TennisGame1 alloc] initWithPlayer1:@"player1" player2:@"player2"]; - [self checkAllScoresForGame:game]; -} - -- (void)testAllScoresTennisGame2 { - TennisGame2 * game = [[TennisGame2 alloc] initWithPlayer1:@"player1" player2:@"player2"]; - [self checkAllScoresForGame:game]; -} - -- (void)testAllScoresTennisGame3 { - TennisGame3 * game = [[TennisGame3 alloc] initWithPlayer1:@"player1" player2:@"player2"]; - [self checkAllScoresForGame:game]; -} - -@end diff --git a/Tennis/python/tennis.py b/Tennis/python/tennis.py deleted file mode 100644 index 3f47d7f7..00000000 --- a/Tennis/python/tennis.py +++ /dev/null @@ -1,175 +0,0 @@ -# -*- coding: utf-8 -*- - -class TennisGame1: - - def __init__(self, player1Name, player2Name): - self.player1Name = player1Name - self.player2Name = player2Name - self.p1points = 0 - self.p2points = 0 - - def won_point(self, playerName): - if playerName == self.player1Name: - self.p1points += 1 - else: - self.p2points += 1 - - def score(self): - result = "" - tempScore=0 - if (self.p1points==self.p2points): - result = { - 0 : "Love-All", - 1 : "Fifteen-All", - 2 : "Thirty-All", - 3 : "Forty-All", - }.get(self.p1points, "Deuce") - elif (self.p1points>=4 or self.p2points>=4): - minusResult = self.p1points-self.p2points - if (minusResult==1): - result ="Advantage " + self.player1Name - elif (minusResult ==-1): - result ="Advantage " + self.player2Name - elif (minusResult>=2): - result = "Win for " + self.player1Name - else: - result ="Win for " + self.player2Name - else: - for i in range(1,3): - if (i==1): - tempScore = self.p1points - else: - result+="-" - tempScore = self.p2points - result += { - 0 : "Love", - 1 : "Fifteen", - 2 : "Thirty", - 3 : "Forty", - }[tempScore] - return result - - -class TennisGame2: - def __init__(self, player1Name, player2Name): - self.player1Name = player1Name - self.player2Name = player2Name - self.p1points = 0 - self.p2points = 0 - - def won_point(self, playerName): - if playerName == self.player1Name: - self.P1Score() - else: - self.P2Score() - - def score(self): - result = "" - if (self.p1points == self.p2points and self.p1points < 4): - if (self.p1points==0): - result = "Love" - if (self.p1points==1): - result = "Fifteen" - if (self.p1points==2): - result = "Thirty" - if (self.p1points==3): - result = "Forty" - result += "-All" - if (self.p1points==self.p2points and self.p1points>3): - result = "Deuce" - - P1res = "" - P2res = "" - if (self.p1points > 0 and self.p2points==0): - if (self.p1points==1): - P1res = "Fifteen" - if (self.p1points==2): - P1res = "Thirty" - if (self.p1points==3): - P1res = "Forty" - - P2res = "Love" - result = P1res + "-" + P2res - if (self.p2points > 0 and self.p1points==0): - if (self.p2points==1): - P2res = "Fifteen" - if (self.p2points==2): - P2res = "Thirty" - if (self.p2points==3): - P2res = "Forty" - - P1res = "Love" - result = P1res + "-" + P2res - - - if (self.p1points>self.p2points and self.p1points < 4): - if (self.p1points==2): - P1res="Thirty" - if (self.p1points==3): - P1res="Forty" - if (self.p2points==1): - P2res="Fifteen" - if (self.p2points==2): - P2res="Thirty" - result = P1res + "-" + P2res - if (self.p2points>self.p1points and self.p2points < 4): - if (self.p2points==2): - P2res="Thirty" - if (self.p2points==3): - P2res="Forty" - if (self.p1points==1): - P1res="Fifteen" - if (self.p1points==2): - P1res="Thirty" - result = P1res + "-" + P2res - - if (self.p1points > self.p2points and self.p2points >= 3): - result = "Advantage " + self.player1Name - - if (self.p2points > self.p1points and self.p1points >= 3): - result = "Advantage " + self.player2Name - - if (self.p1points>=4 and self.p2points>=0 and (self.p1points-self.p2points)>=2): - result = "Win for " + self.player1Name - if (self.p2points>=4 and self.p1points>=0 and (self.p2points-self.p1points)>=2): - result = "Win for " + self.player2Name - return result - - def SetP1Score(self, number): - for i in range(number): - self.P1Score() - - def SetP2Score(self, number): - for i in range(number): - self.P2Score() - - def P1Score(self): - self.p1points +=1 - - - def P2Score(self): - self.p2points +=1 - -class TennisGame3: - def __init__(self, player1Name, player2Name): - self.p1N = player1Name - self.p2N = player2Name - self.p1 = 0 - self.p2 = 0 - - def won_point(self, n): - if n == self.p1N: - self.p1 += 1 - else: - self.p2 += 1 - - def score(self): - if (self.p1 < 4 and self.p2 < 4): - p = ["Love", "Fifteen", "Thirty", "Forty"] - s = p[self.p1] - return s + "-All" if (self.p1 == self.p2) else s + "-" + p[self.p2] - else: - if (self.p1 == self.p2): - return "Deuce" - s = self.p1N if self.p1 > self.p2 else self.p2N - return "Advantage " + s if ((self.p1-self.p2)*(self.p1-self.p2) == 1) else "Win for " + s diff --git a/Tennis/python/tennis_test.py b/Tennis/python/tennis_test.py deleted file mode 100644 index ccc5c099..00000000 --- a/Tennis/python/tennis_test.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- - -import pytest -from tennis import TennisGame1, TennisGame2, TennisGame3 - -from tennis_unittest import test_cases, play_game - -class TestTennis: - - @pytest.mark.parametrize('p1Points p2Points score p1Name p2Name'.split(), test_cases) - def test_get_score_game1(self, p1Points, p2Points, score, p1Name, p2Name): - game = play_game(TennisGame1, p1Points, p2Points, p1Name, p2Name) - assert score == game.score() - - @pytest.mark.parametrize('p1Points p2Points score p1Name p2Name'.split(), test_cases) - def test_get_score_game2(self, p1Points, p2Points, score, p1Name, p2Name): - game = play_game(TennisGame2, p1Points, p2Points, p1Name, p2Name) - assert score == game.score() - - @pytest.mark.parametrize('p1Points p2Points score p1Name p2Name'.split(), test_cases) - def test_get_score_game3(self, p1Points, p2Points, score, p1Name, p2Name): - game = play_game(TennisGame3, p1Points, p2Points, p1Name, p2Name) - assert score == game.score() diff --git a/Tennis/python/tennis_unittest.py b/Tennis/python/tennis_unittest.py deleted file mode 100644 index 91ff3fe8..00000000 --- a/Tennis/python/tennis_unittest.py +++ /dev/null @@ -1,85 +0,0 @@ -# -*- coding: utf-8 -*- - -import unittest - -from tennis import TennisGame1, TennisGame2, TennisGame3 - -test_cases = [ - (0, 0, "Love-All", 'player1', 'player2'), - (1, 1, "Fifteen-All", 'player1', 'player2'), - (2, 2, "Thirty-All", 'player1', 'player2'), - (3, 3, "Forty-All", 'player1', 'player2'), - (4, 4, "Deuce", 'player1', 'player2'), - - (1, 0, "Fifteen-Love", 'player1', 'player2'), - (0, 1, "Love-Fifteen", 'player1', 'player2'), - (2, 0, "Thirty-Love", 'player1', 'player2'), - (0, 2, "Love-Thirty", 'player1', 'player2'), - (3, 0, "Forty-Love", 'player1', 'player2'), - (0, 3, "Love-Forty", 'player1', 'player2'), - (4, 0, "Win for player1", 'player1', 'player2'), - (0, 4, "Win for player2", 'player1', 'player2'), - - (2, 1, "Thirty-Fifteen", 'player1', 'player2'), - (1, 2, "Fifteen-Thirty", 'player1', 'player2'), - (3, 1, "Forty-Fifteen", 'player1', 'player2'), - (1, 3, "Fifteen-Forty", 'player1', 'player2'), - (4, 1, "Win for player1", 'player1', 'player2'), - (1, 4, "Win for player2", 'player1', 'player2'), - - (3, 2, "Forty-Thirty", 'player1', 'player2'), - (2, 3, "Thirty-Forty", 'player1', 'player2'), - (4, 2, "Win for player1", 'player1', 'player2'), - (2, 4, "Win for player2", 'player1', 'player2'), - - (4, 3, "Advantage player1", 'player1', 'player2'), - (3, 4, "Advantage player2", 'player1', 'player2'), - (5, 4, "Advantage player1", 'player1', 'player2'), - (4, 5, "Advantage player2", 'player1', 'player2'), - (15, 14, "Advantage player1", 'player1', 'player2'), - (14, 15, "Advantage player2", 'player1', 'player2'), - - (6, 4, 'Win for player1', 'player1', 'player2'), - (4, 6, 'Win for player2', 'player1', 'player2'), - (16, 14, 'Win for player1', 'player1', 'player2'), - (14, 16, 'Win for player2', 'player1', 'player2'), - - (6, 4, 'Win for One', 'One', 'player2'), - (4, 6, 'Win for Two', 'player1', 'Two'), - (6, 5, 'Advantage One', 'One', 'player2'), - (5, 6, 'Advantage Two', 'player1', 'Two'), - - ] - -def play_game(TennisGame, p1Points, p2Points, p1Name, p2Name): - game = TennisGame(p1Name, p2Name) - for i in range(max(p1Points, p2Points)): - if i < p1Points: - game.won_point(p1Name) - if i < p2Points: - game.won_point(p2Name) - return game - -class TestTennis(unittest.TestCase): - - def test_Score_Game1(self): - for testcase in test_cases: - (p1Points, p2Points, score, p1Name, p2Name) = testcase - game = play_game(TennisGame1, p1Points, p2Points, p1Name, p2Name) - self.assertEquals(score, game.score()) - - def test_Score_Game2(self): - for testcase in test_cases: - (p1Points, p2Points, score, p1Name, p2Name) = testcase - game = play_game(TennisGame2, p1Points, p2Points, p1Name, p2Name) - self.assertEquals(score, game.score()) - - def test_Score_Game3(self): - for testcase in test_cases: - (p1Points, p2Points, score, p1Name, p2Name) = testcase - game = play_game(TennisGame3, p1Points, p2Points, p1Name, p2Name) - self.assertEquals(score, game.score()) - -if __name__ == "__main__": - unittest.main() - \ No newline at end of file diff --git a/Tennis/ruby/tennis.rb b/Tennis/ruby/tennis.rb deleted file mode 100644 index d9dd6c98..00000000 --- a/Tennis/ruby/tennis.rb +++ /dev/null @@ -1,223 +0,0 @@ - -class TennisGame1 - - def initialize(player1Name, player2Name) - @player1Name = player1Name - @player2Name = player2Name - @p1points = 0 - @p2points = 0 - end - - def won_point(playerName) - if playerName == @player1Name - @p1points += 1 - else - @p2points += 1 - end - end - - def score - result = "" - tempScore=0 - if (@p1points==@p2points) - result = { - 0 => "Love-All", - 1 => "Fifteen-All", - 2 => "Thirty-All", - 3 => "Forty-All", - }.fetch(@p1points, "Deuce") - elsif (@p1points>=4 or @p2points>=4) - minusResult = @p1points-@p2points - if (minusResult==1) - result ="Advantage " + @player1Name - elsif (minusResult ==-1) - result ="Advantage " + @player2Name - elsif (minusResult>=2) - result = "Win for " + @player1Name - else - result ="Win for " + @player2Name - end - else - (1...3).each do |i| - if (i==1) - tempScore = @p1points - else - result+="-" - tempScore = @p2points - end - result += { - 0 => "Love", - 1 => "Fifteen", - 2 => "Thirty", - 3 => "Forty", - }[tempScore] - end - end - result - end -end - -class TennisGame2 - def initialize(player1Name, player2Name) - @player1Name = player1Name - @player2Name = player2Name - @p1points = 0 - @p2points = 0 - end - - def won_point(playerName) - if playerName == @player1Name - p1Score() - else - p2Score() - end - end - - def score - result = "" - if (@p1points == @p2points and @p1points < 4) - if (@p1points==0) - result = "Love" - end - if (@p1points==1) - result = "Fifteen" - end - if (@p1points==2) - result = "Thirty" - end - if (@p1points==3) - result = "Forty" - end - result += "-All" - end - if (@p1points==@p2points and @p1points>3) - result = "Deuce" - end - - p1res = "" - p2res = "" - if (@p1points > 0 and @p2points==0) - if (@p1points==1) - p1res = "Fifteen" - end - if (@p1points==2) - p1res = "Thirty" - end - if (@p1points==3) - p1res = "Forty" - end - p2res = "Love" - result = p1res + "-" + p2res - end - if (@p2points > 0 and @p1points==0) - if (@p2points==1) - p2res = "Fifteen" - end - if (@p2points==2) - p2res = "Thirty" - end - if (@p2points==3) - p2res = "Forty" - end - - p1res = "Love" - result = p1res + "-" + p2res - end - - if (@p1points>@p2points and @p1points < 4) - if (@p1points==2) - p1res="Thirty" - end - if (@p1points==3) - p1res="Forty" - end - if (@p2points==1) - p2res="Fifteen" - end - if (@p2points==2) - p2res="Thirty" - end - result = p1res + "-" + p2res - end - if (@p2points>@p1points and @p2points < 4) - if (@p2points==2) - p2res="Thirty" - end - if (@p2points==3) - p2res="Forty" - end - if (@p1points==1) - p1res="Fifteen" - end - if (@p1points==2) - p1res="Thirty" - end - result = p1res + "-" + p2res - end - if (@p1points > @p2points and @p2points >= 3) - result = "Advantage " + @player1Name - end - if (@p2points > @p1points and @p1points >= 3) - result = "Advantage " + @player2Name - end - if (@p1points>=4 and @p2points>=0 and (@p1points-@p2points)>=2) - result = "Win for " + @player1Name - end - if (@p2points>=4 and @p1points>=0 and (@p2points-@p1points)>=2) - result = "Win for " + @player2Name - end - result - end - - def setp1Score(number) - (0..number).each do |i| - p1Score() - end - end - - def setp2Score(number) - (0..number).each do |i| - p2Score() - end - end - - def p1Score - @p1points +=1 - end - - def p2Score - @p2points +=1 - end -end - -class TennisGame3 - def initialize(player1Name, player2Name) - @p1N = player1Name - @p2N = player2Name - @p1 = 0 - @p2 = 0 - end - - def won_point(n) - if n == @p1N - @p1 += 1 - else - @p2 += 1 - end - end - - def score - if (@p1 < 4 and @p2 < 4) - p = ["Love", "Fifteen", "Thirty", "Forty"] - s = p[@p1] - @p1 == @p2 ? s + "-All" : s + "-" + p[@p2] - else - if (@p1 == @p2) - "Deuce" - else - s = @p1 > @p2 ? @p1N : @p2N - (@p1-@p2)*(@p1-@p2) == 1 ? "Advantage " + s : "Win for " + s - end - end - end -end diff --git a/Tennis/ruby/tennis_test.rb b/Tennis/ruby/tennis_test.rb deleted file mode 100644 index df696c1b..00000000 --- a/Tennis/ruby/tennis_test.rb +++ /dev/null @@ -1,86 +0,0 @@ -require File.join(File.dirname(__FILE__), 'tennis') -#require_relative("tennis") -require 'test/unit' - -TEST_CASES = [ - [0, 0, "Love-All", 'player1', 'player2'], - [1, 1, "Fifteen-All", 'player1', 'player2'], - [2, 2, "Thirty-All", 'player1', 'player2'], - [3, 3, "Forty-All", 'player1', 'player2'], - [4, 4, "Deuce", 'player1', 'player2'], - - [1, 0, "Fifteen-Love", 'player1', 'player2'], - [0, 1, "Love-Fifteen", 'player1', 'player2'], - [2, 0, "Thirty-Love", 'player1', 'player2'], - [0, 2, "Love-Thirty", 'player1', 'player2'], - [3, 0, "Forty-Love", 'player1', 'player2'], - [0, 3, "Love-Forty", 'player1', 'player2'], - [4, 0, "Win for player1", 'player1', 'player2'], - [0, 4, "Win for player2", 'player1', 'player2'], - - [2, 1, "Thirty-Fifteen", 'player1', 'player2'], - [1, 2, "Fifteen-Thirty", 'player1', 'player2'], - [3, 1, "Forty-Fifteen", 'player1', 'player2'], - [1, 3, "Fifteen-Forty", 'player1', 'player2'], - [4, 1, "Win for player1", 'player1', 'player2'], - [1, 4, "Win for player2", 'player1', 'player2'], - - [3, 2, "Forty-Thirty", 'player1', 'player2'], - [2, 3, "Thirty-Forty", 'player1', 'player2'], - [4, 2, "Win for player1", 'player1', 'player2'], - [2, 4, "Win for player2", 'player1', 'player2'], - - [4, 3, "Advantage player1", 'player1', 'player2'], - [3, 4, "Advantage player2", 'player1', 'player2'], - [5, 4, "Advantage player1", 'player1', 'player2'], - [4, 5, "Advantage player2", 'player1', 'player2'], - [15, 14, "Advantage player1", 'player1', 'player2'], - [14, 15, "Advantage player2", 'player1', 'player2'], - - [6, 4, 'Win for player1', 'player1', 'player2'], - [4, 6, 'Win for player2', 'player1', 'player2'], - [16, 14, 'Win for player1', 'player1', 'player2'], - [14, 16, 'Win for player2', 'player1', 'player2'], - - [6, 4, 'Win for One', 'One', 'player2'], - [4, 6, 'Win for Two', 'player1', 'Two'], - [6, 5, 'Advantage One', 'One', 'player2'], - [5, 6, 'Advantage Two', 'player1', 'Two'] -] - -class TestTennis < Test::Unit::TestCase - def play_game(tennisGameClass, p1Points, p2Points, p1Name, p2Name) - game = tennisGameClass.new(p1Name, p2Name) - (0..[p1Points, p2Points].max).each do |i| - if i < p1Points - game.won_point(p1Name) - end - if i < p2Points - game.won_point(p2Name) - end - end - game - end - - def test_Score_Game1 - TEST_CASES.each do |testcase| - (p1Points, p2Points, score, p1Name, p2Name) = testcase - game = play_game(TennisGame1, p1Points, p2Points, p1Name, p2Name) - assert_equal(score, game.score()) - end - end - def test_Score_Game2 - TEST_CASES.each do |testcase| - (p1Points, p2Points, score, p1Name, p2Name) = testcase - game = play_game(TennisGame2, p1Points, p2Points, p1Name, p2Name) - assert_equal(score, game.score()) - end - end - def test_Score_Game3 - TEST_CASES.each do |testcase| - (p1Points, p2Points, score, p1Name, p2Name) = testcase - game = play_game(TennisGame3, p1Points, p2Points, p1Name, p2Name) - assert_equal(score, game.score()) - end - end -end \ No newline at end of file diff --git a/Yahtzee/README.md b/Yahtzee/README.md deleted file mode 100644 index 8a7575fb..00000000 --- a/Yahtzee/README.md +++ /dev/null @@ -1,116 +0,0 @@ -# Yahtzee Refactoring Kata - -This Refactoring Kata was designed by Jon Jagger and is available in his Cyber-Dojo. See [his blog post](http://jonjagger.blogspot.co.uk/2012/05/yahtzee-cyber-dojo-refactoring-in-java.html) - -The other language translations have been contributed by: - -Python: Emily Bache - -Ruby: Kim Persson and Lennart Fridén - -## Kata: Yahtzee rules - -The game of yahtzee is a simple dice game. Each player -rolls five six-sided dice. They can re-roll some or all -of the dice up to three times (including the original roll). - -For example, suppose a players rolls - 3,4,5,5,2 -They hold (-,-,5,5,-) and re-roll (3,4,-,-,2) - 5,1,5,5,3 -They hold (5,-,5,5,-) and re-roll (-,1,-,-,3) - 5,6,5,5,2 - -The player then places the roll in a category, such as ones, -twos, fives, pair, two pairs etc (see below). If the roll is -compatible with the category, the player gets a score for the -roll according to the rules. If the roll is not compatible -with the category, the player scores zero for the roll. - -For example, suppose a player scores 5,6,5,5,2 in the fives -category they would score 15 (three fives). The score for -that go is then added to their total and the category cannot -be used again in the remaining goes for that game. -A full game consists of one go for each category. Thus, for -their last go in a game, a player must choose their only -remaining category. - -Your task is to score a GIVEN roll in a GIVEN category. -You do NOT have to program the random dice rolling. -The game is NOT played by letting the computer choose the -highest scoring category for a given roll. - - -## Kata: Yahzee Categories and Scoring Rules - -_Note these rules differ from the original (copyrighted) rules_ - -Chance: - The player scores the sum of all dice, - no matter what they read. - For example, - 1,1,3,3,6 placed on "chance" scores 14 (1+1+3+3+6) - 4,5,5,6,1 placed on "chance" scores 21 (4+5+5+6+1) - -Yahtzee: - If all dice have the same number, - the player scores 50 points. - For example, - 1,1,1,1,1 placed on "yahtzee" scores 50 - 1,1,1,2,1 placed on "yahtzee" scores 0 - -Ones, Twos, Threes, Fours, Fives, Sixes: - The player scores the sum of the dice that reads one, - two, three, four, five or six, respectively. - For example, - 1,1,2,4,4 placed on "fours" scores 8 (4+4) - 2,3,2,5,1 placed on "twos" scores 4 (2+2) - 3,3,3,4,5 placed on "ones" scores 0 - -Pair: - The player scores the sum of the two highest matching dice. - For example, when placed on "pair" - 3,3,3,4,4 scores 8 (4+4) - 1,1,6,2,6 scores 12 (6+6) - 3,3,3,4,1 scores 0 - 3,3,3,3,1 scores 0 - -Two pairs: - If there are two pairs of dice with the same number, the - player scores the sum of these dice. - For example, when placed on "two pairs" - 1,1,2,3,3 scores 8 (1+1+3+3) - 1,1,2,3,4 scores 0 - 1,1,2,2,2 scores 0 - -Three of a kind: - If there are three dice with the same number, the player - scores the sum of these dice. - For example, when placed on "three of a kind" - 3,3,3,4,5 scores 9 (3+3+3) - 3,3,4,5,6 scores 0 - 3,3,3,3,1 scores 0 - -Four of a kind: - If there are four dice with the same number, the player - scores the sum of these dice. - For example, when placed on "four of a kind" - 2,2,2,2,5 scores 8 (2+2+2+2) - 2,2,2,5,5 scores 0 - 2,2,2,2,2 scores 0 - -Small straight: - When placed on "small straight", if the dice read - 1,2,3,4,5, the player scores 15 (the sum of all the dice. - -Large straight: - When placed on "large straight", if the dice read - 2,3,4,5,6, the player scores 20 (the sum of all the dice). - -Full house: - If the dice are two of a kind and three of a kind, the - player scores the sum of all the dice. - For example, when placed on "full house" - 1,1,2,2,2 scores 8 (1+1+2+2+2) - 2,2,3,3,4 scores 0 - 4,4,4,4,4 scores 0 diff --git a/Yahtzee/cpp/makefile b/Yahtzee/cpp/makefile deleted file mode 100644 index 29429df5..00000000 --- a/Yahtzee/cpp/makefile +++ /dev/null @@ -1,6 +0,0 @@ -run.tests.output : run.tests - ./run.tests - -run.tests : *.cpp - g++ -Wall -Werror -O *.cpp -o run.tests - diff --git a/Yahtzee/cpp/run.tests b/Yahtzee/cpp/run.tests deleted file mode 100755 index 7f78da1fc3afbaf3b70df68ef0c7528c1873b89b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 24820 zcmeHP4|G)3nZIvl2%`ojC@QwKq$-*yhD^dhphjn41|~H^B!~#o$1qGtx|2+pKOu0i z8$045jbmx0UDsM=x2?pi?zX01***czI*SRdG93z z@N`elo-;S+y?ej=`@Zjf_q%`IefPf1YiIs=b|hnpm9Y*BV{A08G&0t)&mqOwHMsn^ zRJG1C+qcL!Z!YB;gJL9yq)1OY3Q*PgzJ>FREL`4g%wv*cY9&9s(L;1Jv!7a>|#YS4>S*wrs|VkSq$V`qmdP`OKl58 z(Ou4^uS95J%x&s-TE2``bwxzijR)x~fjsr&agv{CeLbnajglBes@f7(W2>8&MZ#)p zJUU39+b#5Es|(t!Ps4=1a9}unby8m=F(VMI*GK-loB$bAwK+naq$#d8BwB)l?CW+5 z`!s(Ot=D&nrYNf~7-@;+JZNr@Ua7A`@)J$-$hiW>MWneo(xTyJeQxv}YL8-#0kPgb z!t_B^m&J0k%HaO8RO-{q4W}Ni;(sQR6S0S!RiCA<}xM|s><*UQXK~wlNF0!NHi=L5xS%3TJpS8cSwY&YY z(KjHk2p1c9DZi+VyK&K+e>1MXchH_k=d*+AU4@J42)83l#x*kM3-}`zUmm>Wma-{j z@JrJ&&cyv?kW-!ppcv%pSI6R^=CT=jxf{Vne)FSU-H7uc?}5Ar@*c>0An$>^2l5`s zdm!(Dya)0g$a^5~fxHL)ejfM|^LPHipL}b;-}QjqpGp*Uo=NUf`hI8iEARU|4;;7o zlYMr7avDo~K&kXZZ0dCOr|YlA7SINSdmyfSn6h1+ve{>(Y;4JH%4u-?sn=2JJL>QE z4N%>>MrQW8);X9Q)BXg8f$<*qW+C%8nEYN2(AhNF!B*l$18Na^_Wka1XU{<|Th{7fGqi_Z4Zy57V9HSkb9D)X8@ z*w2f&kV2jNk`J7;bcU^I8YJJvEHxOe*#J3*%-Q+3e$^4=w_=}8f zy(jZZP4E?-c&#S*8c)1h6MPkk%*+1Z%ZQ!(oCl8=IL2dipGclAc;K_iT~>c;rINgD zy)|*XbH6|NbNgb?{hlSBFM8A^yD`ZANM1g_#kc*RT5Q{pv)3l=wOzQqcl}E5Ap=(X;#AKT$mYp~S78^(VSo z?U)ihTS58OzeLIHG>m)>Z=bhoVWB7aSIbYy3UvQNo-LefzqhNd$U_QW;Pf7z?#2c> zxV(qD++#73did}sI&Sr@|B&X&jeRtAzOXMfwg&kJJd|uUi*QL6UqmDN@9$1$kfU- z0ETMmAzENMeE&CSfn>W)NnDp~w=0RyB-;y>#8t`mA|+9Tsj7Xf(oG!~6UlLlv)5$m zg^kmV@XX)B$|`OoOofp!6-L5TZe)?tP2L~cNLm{3pjpf3K<962Q?BQV8LRE8z6=rO zrx}^Cm9?Fjoj3+(>0jcM#-H4c^~PV@6L>gPzm20Df7i9|P}KQm`kTOaQlWk@Q1%-GI*eS;htjdo;B#=RDXD*=QG^4QLB-aeisircyF*tu+;H~lSchB|QyiwbcmEMViQh4k80;VJTo*M+*L-5lAeptZ2g>!o7G!=dArv!Hh zc!hv>5qzV7cMu!^>=@sH97GRM#0=x75@vGGa98sBc=#e~JFoFmC&`~SIerR=nGZJZ ze7bQqPd8^?$(b+Jjh{|>)TLY#$*Nnx4Wqw|tn|wmEvWLB1U!o1i30vdf;R&mG=9W* zPofNS`%~ebZt4o@8@UMu(%uEcOsJR~cxR!TWIp|8s$8MY-qrMANV(R+X+2Ib!rnGy zr9Um~T_oTo1Xl?79|`^lbA!=d&w~0F>5-cLPeA_8-8*xA6eCGYQ#^}LR($61cOFUq zyRgWy?pu%*3O4E#aAr+j^mva@uoWGb6nu#*uqWDu@Vz?W9vUDJmeV7jB!zH73g60w zZHYyTJzre1`?%#emRx&Cs|{*uJ3ma1CUvRmm-+1HS^%f?(6>79(q3ex|AHC=-Ynp$ z1k<@Q-~$A|F5r}a#}PbDz;6)z6TsQ|9sZ*!Uex02BzRsQ{s^6ujQzp;)T);{)=_Ww zrg;9`Q;0mk!} z#xr?qT(+{JesIR1j`mfI2y)V{6MQPq)s?RZjdHSU-77`D1`&E;UxZ=?cG4u7^$!tZ z){rvSOPR%7=JJFO{u#HJKQq3C!GpS9LzVH0$~=awG)+42)G7g=LDhPE0^UgQKMQ!F zfPX{qECGL$;5C5t^IO&*RN1)$nGE*?p9ZwXhXi`nk?nlm7yt`Zjyr^8K20(N?G(dC z@QH~-R&ocIxl}lWWZwCcl;O_Q1PzW^&t(er4*8f5DwmzAbf>7&8DypZ4F$s?ZwmMr z%q~~+{iV_w45qFiw zoa57th4f8e#(E&PTslYtHRY-%W9A8CUPD&;Fs3?G<;Md4EWz~xK1A@(0H14p_t<-S zdqvyjX7ltyZto?D1>D{SFmsSs?nP=jZn+Rk-@=(42|ss$S(oStBSoEPjU$$TZD<$N ziTv5KP#7IUR+`posMEay{sO`HZV6eV))IUSeFt!rfNvofpG6T&qc;5#V10ib#v<}E zJ*8@LmEv7XUo$J`8JqBOJvsmII?1Qq5i}-R%gsmOIJ5z3^%yGAqYAsOL{_>&n0*@d z0*({BRKV0~=_>^MhJf!OI3VDg2tJ8tZ3BM?Vhxb1Xv>eBK)?yX9-g4a*QH(ke6LIg>Q^k_9~0anU?0Kr1Wey@!#f)ZjtF=G!Igls^@HCB(pSKCvC1V| zdmx}K`MB+uqEjVLT`uQ~xBq9@ivBl-r(wRh6zX8cC^91<%(xoq^k$x}KF*DGy@#l$ zO~Azjr;s+!7pdy!vD{s9Y&J0M#Z~wI3YUD7mc!Qx&HFN$jPnD3>dN8+naq-7Gmx8^ zupCRz%!CGhZ{&AcpJpb6`MrhTTlqc8?{R)_CZl2&r`8pgvtxD&FEsCHcR;U*8? zz@3nniFzK_!<3+q`F5%GCQ48Zd7uRG{*0*4<9eSGS}2Z(V)0mUYakX2Ek|ZUA{_Qd z60s0l9cYZN35CiyLs_u3m5Vs5imR)O?-N)_Y1u4|zhuh93jQ~RJj%+?#a1z~a^mEP zu8D$;g#*zQq560<(6pj44!H`w;PmOWdYBi%rAv)`u*1k`DunFGS#8$ppHHyS z5aCFJKg^6SvQ}7PZ0;e{$$G_CMbx@LQxvY?!8yfb$f^jz+!@(Qf>W=b%rLOQAH0&_ zi?oE)R-Jy6`ubob8j=M}=GM#p>ogURW28!Eo5k3EFvQ3=W#SZRO020p6vO|{#Aq-e z7}QUO&uHwpO3OH3NhvefNhlQQapQO;P?VKbAc|oPO>H6i4qnu!q$RW}JIHgTmfm{% zEaF4C#`cwFQNbF6)NAOECER#npox$AyT0C{zYk*v@xu;29Svfmj_xWYb0r&_Ox>mA zW@EiL8!?t;`N;Ds@ATviX7sP@?=d;>F|4)jGpK!ePmYz)$mf3=BiCOM6ZYh$QS{54 zR_a>je#IHY1dDqqn@@H+V=Sj)ZVMVFHzQGfotRIJ!z9b(6vNNhze>wEE@pBuj=A54 zD8xAtf3QAi8`4{&Q&(W34wru3Y@LNg=z0m5cvlDRAQ-S{7QF zZK<7E2kcmejAF|E(I}>fS?HuoVak|*VjXi}AuSzv@rbnLfwE>EQ*fYBR5;SU0r*5< zWbOVVSWX~7fe1Dd9$oaX#b!lf6fF!X5PvPMtw%U}W+i1(7>0i>;FFSnI%gi9e>32- zlAjhZJPf1%Fc=Ds3VW&~`*8LYqH3chzgDl|_-_OMThg8j;SYnqNAi0vz@8_;|BB?N zogyBFsqZV`f8!$fKLUSR@`o=#|3q}%8>D}>orixi@cY64tmNN%E`A#}w^(xIBL%4u zkJ`RwB{_Oix$d_a9=2SB+$)fKLdwz7ng_GLhA5AE@=KpUj^4q}NVx~$%L^@!-ZZ_x z7xjBaiVf;#L)f_)a$BX`_b*V6#xMnCOBhauN1<J6f_q(xH~+;hJE5-02K92BIn* zsK;Y9L7#6P@+y}FVogCcf?t#i1)6K-tMkiMU;Px7ap~pZx;EC~=joO}v&d{&B@*h2 z_I4FNkr#`!1j0@6)oNQg>)0grJ~A0)!{u)J@hAS{eCjeB5aY-6Hjq=vEUx(OXooU{ zYR&P{I$onW^^tJQS2t^3eWYIXK}B?-E+3|_=u(*xuWE|KRMaRmxduN|Hq+^ABe-#B z*el^y4%f%Sv6>5WQgA+8bbt{1 zfekx&_}R2g*u)t*g*`Bp{i`yW?NMg36N-y{*D{U0ZgH}Qt;`~h(|k=7*mo3h>M6;0 z6)QUm4HkKL=c{XCeTqDRmpl(zt?Yf`p@T=6_dDXzh$$kqRW+U;6#mb(j zfd0dDd!iB|+4Fg6)JK-=mo75rWoSQC3I3mBZ`NADt1iEUkQ_g;I&~jb$jlwqO12-O zr(6(yZYpkXRN=O38j(0{vlzZ)kwRy!h7Uz#ZW0G1o2wyr@OIof+z<}3f3mf)@8Dlq zdcUIJ|62C)`+j~uggctleR*_xRaHU3jN5MyZ&S7^Ta?DeuUMZ^eyD6fy4SMbvW3T6 zEF18*MHx``D@XCSMJYz7ppG#bdbIsK`qqeOZC}qVX>EURj-<7HzWX&??)OC`t?m0g zC~0l~k3KUa{n|d@(~{Qq1Ai!KZC{YSaw7g#xj#r}5=3kJgvTVU?H8Vvw6H z+dsTs(wpQy=0r(r`7f;afPOpOExsd^JZj?adSayzzp5Q_{=v864psNct&BQ`-^$ z{nrTmdP#pu(p8dvLeh6h`smeye}$x9m--%*v{%~qq@>@M{M#gbGyWHg>^UImLsI{H zl3w%~fm`8wvTv-!$4Yva#7iYTTH@1*hCj9QfLRIa&Z<*-g0;BwWCVB&>JF@y8H_=a<=x2m{ z*8XiKdY7QH`VN`!H%+t~)%M_;fomqNS-587^5d$(^#xpa;G%ybpzki`;PT?~;kpag zTwDllH*OcJr({n}B>G<=GwWg5O06`9kr z->ed?#)A!NITEvL=g#ods%nkOmqfE?&eZ)pb2wDR%sJD@bBk(q>U>oy{}o(S6_B&i zSo~nzX!Bs)SkXcFApe*-sx&^P^&pT$7J1d*pRPV8SC?1{A)_AWR00}oomR{*1`JBDTZad0WqxT z^~hA1LLbD+wWtBoE%^2M)67d~1881x>p{HaiB-NS(^%n|6+>}VaJS@MZtx4&gWiKw z?KMfv72 - -int Yahtzee::Chance(int d1, int d2, int d3, int d4, int d5) -{ - int total = 0; - total += d1; - total += d2; - total += d3; - total += d4; - total += d5; - return total; -} - - -int Yahtzee::yahtzee(int dice[]) -{ - int counts[6] = {0,0,0,0,0,0}; - for (int i = 0; i != 5; i++) - counts[dice[i]-1]++; - for (int i = 0; i != 6; i++) - if (counts[i] == 5) - return 50; - return 0; -} - -int Yahtzee::Ones(int d1, int d2, int d3, int d4, int d5) { - int sum = 0; - if (d1 == 1) sum++; - if (d2 == 1) sum++; - if (d3 == 1) sum++; - if (d4 == 1) sum++; - if (d5 == 1) - sum++; - - return sum; -} - -int Yahtzee::Twos(int d1, int d2, int d3, int d4, int d5) { - int sum = 0; - if (d1 == 2) sum += 2; - if (d2 == 2) sum += 2; - if (d3 == 2) sum += 2; - if (d4 == 2) sum += 2; - if (d5 == 2) sum += 2; - return sum; -} - - -int Yahtzee::Threes(int d1, int d2, int d3, int d4, int d5) { - int s; - s = 0; - if (d1 == 3) s += 3; - if (d2 == 3) s += 3; - if (d3 == 3) s += 3; - if (d4 == 3) s += 3; - if (d5 == 3) s += 3; - return s; -} - -Yahtzee::Yahtzee() -{ -} - -Yahtzee::Yahtzee(int d1, int d2, int d3, int d4, int _5) -{ - dice = new int[5]; - dice[0] = d1; - dice[1] = d2; - dice[2] = d3; - dice[3] = d4; - dice[4] = _5; -} - -int Yahtzee::Fours() -{ - int sum; - sum = 0; - for (int at = 0; at != 5; at++) { - if (dice[at] == 4) { - sum += 4; - } - } - return sum; -} - - -int Yahtzee::Fives() -{ - int s = 0; - int i; - for (i = 0; i < 5; i++) - if (dice[i] == 5) - s = s + 5; - return s; -} - -int Yahtzee::sixes() -{ - int sum = 0; - for (int at = 0; at < 5; at++) - if (dice[at] == 6) - sum = sum + 6; - return sum; -} - -int Yahtzee::ScorePair(int d1, int d2, int d3, int d4, int d5) -{ - int counts[6] = {0,0,0,0,0,0}; - counts[d1-1]++; - counts[d2-1]++; - counts[d3-1]++; - counts[d4-1]++; - counts[d5-1]++; - int at; - for (at = 0; at != 6; at++) - if (counts[6-at-1] == 2) - return (6-at)*2; - return 0; -} - -int Yahtzee::TwoPair(int d1, int d2, int d3, int d4, int d5) -{ - int counts[6] = {0}; - counts[d1-1]++; - counts[d2-1]++; - counts[d3-1]++; - counts[d4-1]++; - counts[d5-1]++; - int n = 0; - int score = 0; - for (int i = 0; i < 6; i += 1) - if (counts[6-i-1] == 2) { - n++; - score += (6-i); - } - if (n == 2) - return score * 2; - else - return 0; -} - -int Yahtzee::FourOfAKind(int _1, int _2, int d3, int d4, int d5) -{ - int * tallies; - tallies = new int[6]; - tallies[0] = tallies[1] = tallies[2] = 0; - tallies[3] = tallies[4] = tallies[5] = 0; - tallies[_1-1]++; - tallies[_2-1]++; - tallies[d3-1]++; - tallies[d4-1]++; - tallies[d5-1]++; - for (int i = 0; i < 6; i++) - if (tallies[i] == 4) - return (i+1) * 4; - return 0; -} - -int Yahtzee::ThreeOfAKind(int d1, int d2, int d3, int d4, int d5) -{ - int * t; - t = new int[6]; - t[0] = t[1] = t[2] = 0; - t[3] = t[4] = t[5] = 0; - t[d1-1]++; - t[d2-1]++; - t[d3-1]++; - t[d4-1]++; - t[d5-1]++; - for (int i = 0; i < 6; i++) - if (t[i] == 3) - return (i+1) * 3; - return 0; -} - - -int Yahtzee::SmallStraight(int d1, int d2, int d3, int d4, int d5) -{ - int* tallies =new int[6]; - memset(tallies, 0, sizeof(int)*6); - tallies[d1-1] += 1; - tallies[d2-1] += 1; - tallies[d3-1] += 1; - tallies[d4-1] += 1; - tallies[d5-1] += 1; - if (tallies[0] == 1 && - tallies[1] == 1 && - tallies[2] == 1 && - tallies[3] == 1 && - tallies[4] == 1) - return 15; - return 0; -} - -int Yahtzee::LargeStraight(int d1, int d2, int d3, int d4, int d5) -{ - int* tallies = new int[6]; - memset(tallies, 0, sizeof(*tallies)*6); - tallies[d1-1] += 1; - tallies[d2-1] += 1; - tallies[d3-1] += 1; - tallies[d4-1] += 1; - tallies[d5-1] += 1; - if (tallies[1] == 1 && - tallies[2] == 1 && - tallies[3] == 1 && - tallies[4] == 1 - && tallies[5] == 1) - return 20; - return 0; -} - - -int Yahtzee::FullHouse(int d1, int d2, int d3, int d4, int d5) -{ - int* tallies; - bool _2 = false; - int i; - int _2_at = 0; - bool _3 = false; - int _3_at = 0; - - - - - tallies = new int[6]; - memset(tallies, 0, sizeof(int)*6); - tallies[d1-1] += 1; - tallies[d2-1] += 1; - tallies[d3-1] += 1; - tallies[d4-1] += 1; - tallies[d5-1] += 1; - - for (i = 0; i != 6; i += 1) - if (tallies[i] == 2) { - _2 = true; - _2_at = i+1; - } - - for (i = 0; i != 6; i += 1) - if (tallies[i] == 3) { - _3 = true; - _3_at = i+1; - } - - if (_2 && _3) - return _2_at * 2 + _3_at * 3; - else - return 0; -} diff --git a/Yahtzee/cpp/yahtzee.hpp b/Yahtzee/cpp/yahtzee.hpp deleted file mode 100644 index c79dce48..00000000 --- a/Yahtzee/cpp/yahtzee.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef YAHTZEE_INCLUDED -#define YATHZEE_INCLUDED - -class Yahtzee -{ -public: - - static int Chance(int d1, int d2, int d3, int d4, int d5); - static int yahtzee(int dice[]); - static int Ones(int d1, int d2, int d3, int d4, int d5); - static int Twos(int d1, int d2, int d3, int d4, int d5); - static int Threes(int d1, int d2, int d3, int d4, int d5); - -protected: - int * dice; -public: - Yahtzee(); - Yahtzee(int d1, int d2, int d3, int d4, int _5); - int Fours(); - int Fives(); - int sixes(); - int ScorePair(int d1, int d2, int d3, int d4, int d5); - static int TwoPair(int d1, int d2, int d3, int d4, int d5); - static int FourOfAKind(int _1, int _2, int d3, int d4, int d5); - static int ThreeOfAKind(int d1, int d2, int d3, int d4, int d5); - - static int SmallStraight(int d1, int d2, int d3, int d4, int d5); - static int LargeStraight(int d1, int d2, int d3, int d4, int d5); - static int FullHouse(int d1, int d2, int d3, int d4, int d5); - -}; - -#endif \ No newline at end of file diff --git a/Yahtzee/cpp/yahtzee.tests.cpp b/Yahtzee/cpp/yahtzee.tests.cpp deleted file mode 100644 index 42878ea9..00000000 --- a/Yahtzee/cpp/yahtzee.tests.cpp +++ /dev/null @@ -1,153 +0,0 @@ -#include "yahtzee.hpp" -#include -#include - -static void Chance_scores_sum_of_all_dice(void) -{ - int expected = 15; - int actual = Yahtzee().Chance(2,3,4,5,1); - assert(expected == actual); - assert(16 == Yahtzee().Chance(3,3,4,5,1)); -} - -static int * ints(int a, int b, int c, int d, int e) -{ - int * r = new int[5]; - r[0] = a; - r[1] = b; - r[2] = c; - r[3] = d; - r[4] = e; - return r; -} - -static void Yahtzee_scores_50(void) -{ - int expected = 50; - int actual = Yahtzee().yahtzee(ints(4,4,4,4,4)); - assert(expected == actual); - assert(50 == Yahtzee().yahtzee(ints(6,6,6,6,6))); - assert(0 == Yahtzee().yahtzee(ints(6,6,6,6,3))); -} - -static void Test_1s() -{ - assert(Yahtzee().Ones(1,2,3,4,5) == 1); - assert(2 == Yahtzee().Ones(1,2,1,4,5)); - assert(0 == Yahtzee().Ones(6,2,2,4,5)); - assert(4 == Yahtzee().Ones(1,2,1,1,1)); -} - -static void test_2s() -{ - assert(4 == Yahtzee().Twos(1,2,3,2,6)); - assert(10 == Yahtzee().Twos(2,2,2,2,2)); -} - -static void test_threes() -{ - assert(6 == Yahtzee().Threes(1,2,3,2,3)); - assert(12 == Yahtzee().Threes(2,3,3,3,3)); -} - -static void fours_test() -{ - assert(12 == (new Yahtzee(4,4,4,5,5))->Fours()); - assert(8 == (new Yahtzee(4,4,5,5,5))->Fours()); - assert(4 == (*new Yahtzee(4,5,5,5,5)).Fours()); -} - -static void fives() { - assert(10 == (new Yahtzee(4,4,4,5,5))->Fives()); - assert(15 == Yahtzee(4,4,5,5,5).Fives()); - assert(20 == Yahtzee(4,5,5,5,5).Fives()); -} - -static void sixes_test() -{ - assert(0 == Yahtzee(4,4,4,5,5).sixes()); - assert(6 == Yahtzee(4,4,6,5,5).sixes()); - assert(18 == Yahtzee(6,5,6,6,5).sixes()); -} - -static void one_pair() -{ - assert(6 == Yahtzee().ScorePair(3,4,3,5,6)); - assert(10 == Yahtzee().ScorePair(5,3,3,3,5)); - assert(12 == Yahtzee().ScorePair(5,3,6,6,5)); -} - -static void two_Pair() -{ - assert(16 == Yahtzee().TwoPair(3,3,5,4,5)); - assert(0 == Yahtzee().TwoPair(3,3,5,5,5)); -} - -static void three_of_a_kind() -{ - assert(9 == Yahtzee().ThreeOfAKind(3,3,3,4,5)); - assert(15 == Yahtzee().ThreeOfAKind(5,3,5,4,5)); - assert(0 == Yahtzee::ThreeOfAKind(3,3,3,3,5)); -} - -static void four_of_a_knd() -{ - assert(12 == Yahtzee::FourOfAKind(3,3,3,3,5)); - assert(20 == Yahtzee::FourOfAKind(5,5,5,4,5)); - assert(0 == Yahtzee::FourOfAKind(3,3,3,3,3)); -} - -static void smallStraight() -{ - assert(15 == Yahtzee::SmallStraight(1,2,3,4,5)); - assert(15 == Yahtzee::SmallStraight(2,3,4,5,1)); - assert(0 == Yahtzee().SmallStraight(1,2,2,4,5)); -} - -static void largeStraight() -{ - assert(20 == Yahtzee::LargeStraight(6,2,3,4,5)); - assert(20 == Yahtzee().LargeStraight(2,3,4,5,6)); - assert(0== Yahtzee::LargeStraight(1,2,2,4,5)); -} - - -static void fullHouse() -{ - assert(18 == Yahtzee().FullHouse(6,2,2,2,6)); - assert(0 == Yahtzee().FullHouse(2,3,4,5,6)); -} - -typedef void test(); - -static test * tests[ ] = -{ - Chance_scores_sum_of_all_dice, - Yahtzee_scores_50, - Test_1s, - test_2s, - test_threes, - fours_test, - fives, - sixes_test, - one_pair, - two_Pair, - three_of_a_kind, - four_of_a_knd, - smallStraight, - largeStraight, - fullHouse, - static_cast(0), -}; - -int main() -{ - size_t at = 0; - while (tests[at]) - { - tests[at++](); - std::cout << '.'; - } - std::cout << std::endl << at << " tests passed" << std::endl; - return 0; -} \ No newline at end of file diff --git a/Yahtzee/csharp/Yahtzee.cs b/Yahtzee/csharp/Yahtzee.cs deleted file mode 100644 index 6f7d8867..00000000 --- a/Yahtzee/csharp/Yahtzee.cs +++ /dev/null @@ -1,238 +0,0 @@ -public class Yahtzee { - - public static int Chance(int d1, int d2, int d3, int d4, int d5) - { - int total = 0; - total += d1; - total += d2; - total += d3; - total += d4; - total += d5; - return total; - } - - public static int yahtzee(params int[] dice) - { - int[] counts = new int[6]; - foreach (int die in dice) - counts[die-1]++; - for (int i = 0; i != 6; i++) - if (counts[i] == 5) - return 50; - return 0; - } - - public static int Ones(int d1, int d2, int d3, int d4, int d5) { - int sum = 0; - if (d1 == 1) sum++; - if (d2 == 1) sum++; - if (d3 == 1) sum++; - if (d4 == 1) sum++; - if (d5 == 1) - sum++; - - return sum; - } - - public static int Twos(int d1, int d2, int d3, int d4, int d5) { - int sum = 0; - if (d1 == 2) sum += 2; - if (d2 == 2) sum += 2; - if (d3 == 2) sum += 2; - if (d4 == 2) sum += 2; - if (d5 == 2) sum += 2; - return sum; - } - - public static int Threes(int d1, int d2, int d3, int d4, int d5) { - int s; - s = 0; - if (d1 == 3) s += 3; - if (d2 == 3) s += 3; - if (d3 == 3) s += 3; - if (d4 == 3) s += 3; - if (d5 == 3) s += 3; - return s; - } - - protected int[] dice; - public Yahtzee(int d1, int d2, int d3, int d4, int _5) - { - dice = new int[5]; - dice[0] = d1; - dice[1] = d2; - dice[2] = d3; - dice[3] = d4; - dice[4] = _5; - } - - public int Fours() - { - int sum; - sum = 0; - for (int at = 0; at != 5; at++) { - if (dice[at] == 4) { - sum += 4; - } - } - return sum; - } - - public int Fives() - { - int s = 0; - int i; - for (i = 0; i < dice.Length; i++) - if (dice[i] == 5) - s = s + 5; - return s; - } - - public int sixes() - { - int sum = 0; - for (int at = 0; at < dice.Length; at++) - if (dice[at] == 6) - sum = sum + 6; - return sum; - } - - public static int ScorePair(int d1, int d2, int d3, int d4, int d5) - { - int[] counts = new int[6]; - counts[d1-1]++; - counts[d2-1]++; - counts[d3-1]++; - counts[d4-1]++; - counts[d5-1]++; - int at; - for (at = 0; at != 6; at++) - if (counts[6-at-1] == 2) - return (6-at)*2; - return 0; - } - - public static int TwoPair(int d1, int d2, int d3, int d4, int d5) - { - int[] counts = new int[6]; - counts[d1-1]++; - counts[d2-1]++; - counts[d3-1]++; - counts[d4-1]++; - counts[d5-1]++; - int n = 0; - int score = 0; - for (int i = 0; i < 6; i += 1) - if (counts[6-i-1] == 2) { - n++; - score += (6-i); - } - if (n == 2) - return score * 2; - else - return 0; - } - - public static int FourOfAKind(int _1, int _2, int d3, int d4, int d5) - { - int[] tallies; - tallies = new int[6]; - tallies[_1-1]++; - tallies[_2-1]++; - tallies[d3-1]++; - tallies[d4-1]++; - tallies[d5-1]++; - for (int i = 0; i < 6; i++) - if (tallies[i] == 4) - return (i+1) * 4; - return 0; - } - - public static int ThreeOfAKind(int d1, int d2, int d3, int d4, int d5) - { - int[] t; - t = new int[6]; - t[d1-1]++; - t[d2-1]++; - t[d3-1]++; - t[d4-1]++; - t[d5-1]++; - for (int i = 0; i < 6; i++) - if (t[i] == 3) - return (i+1) * 3; - return 0; - } - - public static int SmallStraight(int d1, int d2, int d3, int d4, int d5) - { - int[] tallies; - tallies = new int[6]; - tallies[d1-1] += 1; - tallies[d2-1] += 1; - tallies[d3-1] += 1; - tallies[d4-1] += 1; - tallies[d5-1] += 1; - if (tallies[0] == 1 && - tallies[1] == 1 && - tallies[2] == 1 && - tallies[3] == 1 && - tallies[4] == 1) - return 15; - return 0; - } - - public static int LargeStraight(int d1, int d2, int d3, int d4, int d5) - { - int[] tallies; - tallies = new int[6]; - tallies[d1-1] += 1; - tallies[d2-1] += 1; - tallies[d3-1] += 1; - tallies[d4-1] += 1; - tallies[d5-1] += 1; - if (tallies[1] == 1 && - tallies[2] == 1 && - tallies[3] == 1 && - tallies[4] == 1 - && tallies[5] == 1) - return 20; - return 0; - } - - public static int FullHouse(int d1, int d2, int d3, int d4, int d5) - { - int[] tallies; - bool _2 = false; - int i; - int _2_at = 0; - bool _3 = false; - int _3_at = 0; - - - - - tallies = new int[6]; - tallies[d1-1] += 1; - tallies[d2-1] += 1; - tallies[d3-1] += 1; - tallies[d4-1] += 1; - tallies[d5-1] += 1; - - for (i = 0; i != 6; i += 1) - if (tallies[i] == 2) { - _2 = true; - _2_at = i+1; - } - - for (i = 0; i != 6; i += 1) - if (tallies[i] == 3) { - _3 = true; - _3_at = i+1; - } - - if (_2 && _3) - return _2_at * 2 + _3_at * 3; - else - return 0; - } -} diff --git a/Yahtzee/csharp/YahtzeeTest.cs b/Yahtzee/csharp/YahtzeeTest.cs deleted file mode 100644 index be63fa6f..00000000 --- a/Yahtzee/csharp/YahtzeeTest.cs +++ /dev/null @@ -1,124 +0,0 @@ -using NUnit.Framework; - -[TestFixture] -public class UntitledTest -{ - [Test] - public void Chance_scores_sum_of_all_dice() - { - int expected = 15; - int actual = Yahtzee.Chance(2,3,4,5,1); - Assert.AreEqual(expected, actual); - Assert.AreEqual(16, Yahtzee.Chance(3,3,4,5,1)); - } - - [Test] - public void Yahtzee_scores_50() - { - int expected = 50; - int actual = Yahtzee.yahtzee(4,4,4,4,4); - Assert.AreEqual(expected, actual); - Assert.AreEqual(50, Yahtzee.yahtzee(6,6,6,6,6)); - Assert.AreEqual(0, Yahtzee.yahtzee(6,6,6,6,3)); - } - - [Test] - public void Test_1s() { - Assert.IsTrue(Yahtzee.Ones(1,2,3,4,5) == 1); - Assert.AreEqual(2, Yahtzee.Ones(1,2,1,4,5)); - Assert.AreEqual(0, Yahtzee.Ones(6,2,2,4,5)); - Assert.AreEqual(4, Yahtzee.Ones(1,2,1,1,1)); - } - - [Test] - public void test_2s() - { - Assert.AreEqual(4, Yahtzee.Twos(1,2,3,2,6)); - Assert.AreEqual(10, Yahtzee.Twos(2,2,2,2,2)); - } - - [Test] - public void test_threes() - { - Assert.AreEqual(6, Yahtzee.Threes(1,2,3,2,3)); - Assert.AreEqual(12, Yahtzee.Threes(2,3,3,3,3)); - } - - [Test] - public void fours_test() - { - Assert.AreEqual(12, new Yahtzee(4,4,4,5,5).Fours()); - Assert.AreEqual(8, new Yahtzee(4,4,5,5,5).Fours()); - Assert.AreEqual(4, new Yahtzee(4,5,5,5,5).Fours()); - } - - [Test] - public void fives() { - Assert.AreEqual(10, new Yahtzee(4,4,4,5,5).Fives()); - Assert.AreEqual(15, new Yahtzee(4,4,5,5,5).Fives()); - Assert.AreEqual(20, new Yahtzee(4,5,5,5,5).Fives()); - } - - [Test] - public void sixes_test() - { - Assert.AreEqual(0, new Yahtzee(4,4,4,5,5).sixes()); - Assert.AreEqual(6, new Yahtzee(4,4,6,5,5).sixes()); - Assert.AreEqual(18, new Yahtzee(6,5,6,6,5).sixes()); - } - - [Test] - public void one_pair() - { - Assert.AreEqual(6, Yahtzee.ScorePair(3,4,3,5,6)); - Assert.AreEqual(10, Yahtzee.ScorePair(5,3,3,3,5)); - Assert.AreEqual(12, Yahtzee.ScorePair(5,3,6,6,5)); - } - - [Test] - public void two_Pair() - { - Assert.AreEqual(16, Yahtzee.TwoPair(3,3,5,4,5)); - Assert.AreEqual(0, Yahtzee.TwoPair(3,3,5,5,5)); - } - - [Test] - public void three_of_a_kind() - { - Assert.AreEqual(9, Yahtzee.ThreeOfAKind(3,3,3,4,5)); - Assert.AreEqual(15, Yahtzee.ThreeOfAKind(5,3,5,4,5)); - Assert.AreEqual(0, Yahtzee.ThreeOfAKind(3,3,3,3,5)); - } - - [Test] - public void four_of_a_knd() - { - Assert.AreEqual(12, Yahtzee.FourOfAKind(3,3,3,3,5)); - Assert.AreEqual(20, Yahtzee.FourOfAKind(5,5,5,4,5)); - Assert.AreEqual(0, Yahtzee.FourOfAKind(3,3,3,3,3)); - } - - [Test] - public void smallStraight() - { - Assert.AreEqual(15, Yahtzee.SmallStraight(1,2,3,4,5)); - Assert.AreEqual(15, Yahtzee.SmallStraight(2,3,4,5,1)); - Assert.AreEqual(0, Yahtzee.SmallStraight(1,2,2,4,5)); - } - - [Test] - public void largeStraight() - { - Assert.AreEqual(20, Yahtzee.LargeStraight(6,2,3,4,5)); - Assert.AreEqual(20, Yahtzee.LargeStraight(2,3,4,5,6)); - Assert.AreEqual(0, Yahtzee.LargeStraight(1,2,2,4,5)); - } - - [Test] - public void fullHouse() - { - Assert.AreEqual(18, Yahtzee.FullHouse(6,2,2,2,6)); - Assert.AreEqual(0, Yahtzee.FullHouse(2,3,4,5,6)); - } -} - diff --git a/Yahtzee/java/Yahtzee.java b/Yahtzee/java/Yahtzee.java deleted file mode 100644 index d200df07..00000000 --- a/Yahtzee/java/Yahtzee.java +++ /dev/null @@ -1,241 +0,0 @@ -public class Yahtzee { - - public static int chance(int d1, int d2, int d3, int d4, int d5) - { - int total = 0; - total += d1; - total += d2; - total += d3; - total += d4; - total += d5; - return total; - } - - public static int yahtzee(int... dice) - { - int[] counts = new int[6]; - for (int die : dice) - counts[die-1]++; - for (int i = 0; i != 6; i++) - if (counts[i] == 5) - return 50; - return 0; - } - - public static int ones(int d1, int d2, int d3, int d4, int d5) { - int sum = 0; - if (d1 == 1) sum++; - if (d2 == 1) sum++; - if (d3 == 1) sum++; - if (d4 == 1) sum++; - if (d5 == 1) - sum++; - - return sum; - } - - public static int twos(int d1, int d2, int d3, int d4, int d5) { - int sum = 0; - if (d1 == 2) sum += 2; - if (d2 == 2) sum += 2; - if (d3 == 2) sum += 2; - if (d4 == 2) sum += 2; - if (d5 == 2) sum += 2; - return sum; - } - - public static int threes(int d1, int d2, int d3, int d4, int d5) { - int s; - s = 0; - if (d1 == 3) s += 3; - if (d2 == 3) s += 3; - if (d3 == 3) s += 3; - if (d4 == 3) s += 3; - if (d5 == 3) s += 3; - return s; - } - - protected int[] dice; - public Yahtzee(int d1, int d2, int d3, int d4, int _5) - { - dice = new int[5]; - dice[0] = d1; - dice[1] = d2; - dice[2] = d3; - dice[3] = d4; - dice[4] = _5; - } - - public int fours() - { - int sum; - sum = 0; - for (int at = 0; at != 5; at++) { - if (dice[at] == 4) { - sum += 4; - } - } - return sum; - } - - public int fives() - { - int s = 0; - int i; - for (i = 0; i < dice.length; i++) - if (dice[i] == 5) - s = s + 5; - return s; - } - - public int sixes() - { - int sum = 0; - for (int at = 0; at < dice.length; at++) - if (dice[at] == 6) - sum = sum + 6; - return sum; - } - - public static int score_pair(int d1, int d2, int d3, int d4, int d5) - { - int[] counts = new int[6]; - counts[d1-1]++; - counts[d2-1]++; - counts[d3-1]++; - counts[d4-1]++; - counts[d5-1]++; - int at; - for (at = 0; at != 6; at++) - if (counts[6-at-1] == 2) - return (6-at)*2; - return 0; - } - - public static int two_pair(int d1, int d2, int d3, int d4, int d5) - { - int[] counts = new int[6]; - counts[d1-1]++; - counts[d2-1]++; - counts[d3-1]++; - counts[d4-1]++; - counts[d5-1]++; - int n = 0; - int score = 0; - for (int i = 0; i < 6; i += 1) - if (counts[6-i-1] == 2) { - n++; - score += (6-i); - } - if (n == 2) - return score * 2; - else - return 0; - } - - public static int four_of_a_kind(int _1, int _2, int d3, int d4, int d5) - { - int[] tallies; - tallies = new int[6]; - tallies[_1-1]++; - tallies[_2-1]++; - tallies[d3-1]++; - tallies[d4-1]++; - tallies[d5-1]++; - for (int i = 0; i < 6; i++) - if (tallies[i] == 4) - return (i+1) * 4; - return 0; - } - - public static int three_of_a_kind(int d1, int d2, int d3, int d4, int d5) - { - int[] t; - t = new int[6]; - t[d1-1]++; - t[d2-1]++; - t[d3-1]++; - t[d4-1]++; - t[d5-1]++; - for (int i = 0; i < 6; i++) - if (t[i] == 3) - return (i+1) * 3; - return 0; - } - - public static int smallStraight(int d1, int d2, int d3, int d4, int d5) - { - int[] tallies; - tallies = new int[6]; - tallies[d1-1] += 1; - tallies[d2-1] += 1; - tallies[d3-1] += 1; - tallies[d4-1] += 1; - tallies[d5-1] += 1; - if (tallies[0] == 1 && - tallies[1] == 1 && - tallies[2] == 1 && - tallies[3] == 1 && - tallies[4] == 1) - return 15; - return 0; - } - - public static int largeStraight(int d1, int d2, int d3, int d4, int d5) - { - int[] tallies; - tallies = new int[6]; - tallies[d1-1] += 1; - tallies[d2-1] += 1; - tallies[d3-1] += 1; - tallies[d4-1] += 1; - tallies[d5-1] += 1; - if (tallies[1] == 1 && - tallies[2] == 1 && - tallies[3] == 1 && - tallies[4] == 1 - && tallies[5] == 1) - return 20; - return 0; - } - - public static int fullHouse(int d1, int d2, int d3, int d4, int d5) - { - int[] tallies; - boolean _2 = false; - int i; - int _2_at = 0; - boolean _3 = false; - int _3_at = 0; - - - - - tallies = new int[6]; - tallies[d1-1] += 1; - tallies[d2-1] += 1; - tallies[d3-1] += 1; - tallies[d4-1] += 1; - tallies[d5-1] += 1; - - for (i = 0; i != 6; i += 1) - if (tallies[i] == 2) { - _2 = true; - _2_at = i+1; - } - - for (i = 0; i != 6; i += 1) - if (tallies[i] == 3) { - _3 = true; - _3_at = i+1; - } - - if (_2 && _3) - return _2_at * 2 + _3_at * 3; - else - return 0; - } -} - - - diff --git a/Yahtzee/java/YahtzeeTest.java b/Yahtzee/java/YahtzeeTest.java deleted file mode 100644 index 15a20a69..00000000 --- a/Yahtzee/java/YahtzeeTest.java +++ /dev/null @@ -1,110 +0,0 @@ -import org.junit.*; -import static org.junit.Assert.*; - -public class YahtzeeTest { - - @Test - public void chance_scores_sum_of_all_dice() { - int expected = 15; - int actual = Yahtzee.chance(2,3,4,5,1); - assertEquals(expected, actual); - assertEquals(16, Yahtzee.chance(3,3,4,5,1)); - } - - @Test public void yahtzee_scores_50() { - int expected = 50; - int actual = Yahtzee.yahtzee(4,4,4,4,4); - assertEquals(expected, actual); - assertEquals(50, Yahtzee.yahtzee(6,6,6,6,6)); - assertEquals(0, Yahtzee.yahtzee(6,6,6,6,3)); - } - - @Test public void test_1s() { - assertTrue(Yahtzee.ones(1,2,3,4,5) == 1); - assertEquals(2, Yahtzee.ones(1,2,1,4,5)); - assertEquals(0, Yahtzee.ones(6,2,2,4,5)); - assertEquals(4, Yahtzee.ones(1,2,1,1,1)); - } - - @Test - public void test_2s() { - assertEquals(4, Yahtzee.twos(1,2,3,2,6)); - assertEquals(10, Yahtzee.twos(2,2,2,2,2)); - } - - @Test - public void test_threes() { - assertEquals(6, Yahtzee.threes(1,2,3,2,3)); - assertEquals(12, Yahtzee.threes(2,3,3,3,3)); - } - - @Test - public void fours_test() - { - assertEquals(12, new Yahtzee(4,4,4,5,5).fours()); - assertEquals(8, new Yahtzee(4,4,5,5,5).fours()); - assertEquals(4, new Yahtzee(4,5,5,5,5).fours()); - } - - @Test - public void fives() { - assertEquals(10, new Yahtzee(4,4,4,5,5).fives()); - assertEquals(15, new Yahtzee(4,4,5,5,5).fives()); - assertEquals(20, new Yahtzee(4,5,5,5,5).fives()); - } - - @Test - public void sixes_test() { - assertEquals(0, new Yahtzee(4,4,4,5,5).sixes()); - assertEquals(6, new Yahtzee(4,4,6,5,5).sixes()); - assertEquals(18, new Yahtzee(6,5,6,6,5).sixes()); - } - - @Test - public void one_pair() { - assertEquals(6, Yahtzee.score_pair(3,4,3,5,6)); - assertEquals(10, Yahtzee.score_pair(5,3,3,3,5)); - assertEquals(12, Yahtzee.score_pair(5,3,6,6,5)); - } - - @Test - public void two_Pair() { - assertEquals(16, Yahtzee.two_pair(3,3,5,4,5)); - assertEquals(0, Yahtzee.two_pair(3,3,5,5,5)); - } - - @Test - public void three_of_a_kind() - { - assertEquals(9, Yahtzee.three_of_a_kind(3,3,3,4,5)); - assertEquals(15, Yahtzee.three_of_a_kind(5,3,5,4,5)); - assertEquals(0, Yahtzee.three_of_a_kind(3,3,3,3,5)); - } - - @Test - public void four_of_a_knd() { - assertEquals(12, Yahtzee.four_of_a_kind(3,3,3,3,5)); - assertEquals(20, Yahtzee.four_of_a_kind(5,5,5,4,5)); - assertEquals(0, Yahtzee.three_of_a_kind(3,3,3,3,3)); - } - - @Test - public void smallStraight() { - assertEquals(15, Yahtzee.smallStraight(1,2,3,4,5)); - assertEquals(15, Yahtzee.smallStraight(2,3,4,5,1)); - assertEquals(0, Yahtzee.smallStraight(1,2,2,4,5)); - } - - @Test - public void largeStraight() { - assertEquals(20, Yahtzee.largeStraight(6,2,3,4,5)); - assertEquals(20, Yahtzee.largeStraight(2,3,4,5,6)); - assertEquals(0, Yahtzee.largeStraight(1,2,2,4,5)); - } - - @Test - public void fullHouse() { - assertEquals(18, Yahtzee.fullHouse(6,2,2,2,6)); - assertEquals(0, Yahtzee.fullHouse(2,3,4,5,6)); - } -} diff --git a/Yahtzee/python/test_yahtzee.py b/Yahtzee/python/test_yahtzee.py deleted file mode 100644 index 5a50b611..00000000 --- a/Yahtzee/python/test_yahtzee.py +++ /dev/null @@ -1,94 +0,0 @@ -from yahtzee import Yahtzee - -# These unit tests can be run using the py.test framework -# available from http://pytest.org/ - -def test_chance_scores_sum_of_all_dice(): - expected = 15 - actual = Yahtzee.chance(2,3,4,5,1) - assert expected == actual - assert 16 == Yahtzee.chance(3,3,4,5,1) - - -def test_yahtzee_scores_50(): - expected = 50 - actual = Yahtzee.yahtzee([4,4,4,4,4]) - assert expected == actual - assert 50 == Yahtzee.yahtzee([6,6,6,6,6]) - assert 0 == Yahtzee.yahtzee([6,6,6,6,3]) - - -def test_1s(): - assert Yahtzee.ones(1,2,3,4,5) == 1 - assert 2 == Yahtzee.ones(1,2,1,4,5) - assert 0 == Yahtzee.ones(6,2,2,4,5) - assert 4 == Yahtzee.ones(1,2,1,1,1) - - -def test_2s(): - assert 4 == Yahtzee.twos(1,2,3,2,6) - assert 10 == Yahtzee.twos(2,2,2,2,2) - - -def test_threes(): - assert 6 == Yahtzee.threes(1,2,3,2,3) - assert 12 == Yahtzee.threes(2,3,3,3,3) - - -def test_fours_test(): - assert 12 == Yahtzee(4,4,4,5,5).fours() - assert 8 == Yahtzee(4,4,5,5,5).fours() - assert 4 == Yahtzee(4,5,5,5,5).fours() - - -def test_fives(): - assert 10 == Yahtzee(4,4,4,5,5).fives() - assert 15 == Yahtzee(4,4,5,5,5).fives() - assert 20 == Yahtzee(4,5,5,5,5).fives() - - -def test_sixes_test(): - assert 0 == Yahtzee(4,4,4,5,5).sixes() - assert 6 == Yahtzee(4,4,6,5,5).sixes() - assert 18 == Yahtzee(6,5,6,6,5).sixes() - - -def test_one_pair(): - assert 6 == Yahtzee.score_pair(3,4,3,5,6) - assert 10 == Yahtzee.score_pair(5,3,3,3,5) - assert 12 == Yahtzee.score_pair(5,3,6,6,5) - - -def test_two_Pair(): - assert 16 == Yahtzee.two_pair(3,3,5,4,5) - assert 0 == Yahtzee.two_pair(3,3,5,5,5) - - -def test_three_of_a_kind(): - assert 9 == Yahtzee.three_of_a_kind(3,3,3,4,5) - assert 15 == Yahtzee.three_of_a_kind(5,3,5,4,5) - assert 0 == Yahtzee.three_of_a_kind(3,3,3,3,5) - - -def test_four_of_a_knd(): - assert 12 == Yahtzee.four_of_a_kind(3,3,3,3,5) - assert 20 == Yahtzee.four_of_a_kind(5,5,5,4,5) - assert 0 == Yahtzee.three_of_a_kind(3,3,3,3,3) - - -def test_smallStraight(): - assert 15 == Yahtzee.smallStraight(1,2,3,4,5) - assert 15 == Yahtzee.smallStraight(2,3,4,5,1) - assert 0 == Yahtzee.smallStraight(1,2,2,4,5) - - -def test_largeStraight(): - assert 20 == Yahtzee.largeStraight(6,2,3,4,5) - assert 20 == Yahtzee.largeStraight(2,3,4,5,6) - assert 0 == Yahtzee.largeStraight(1,2,2,4,5) - - -def test_fullHouse(): - assert 18 == Yahtzee.fullHouse(6,2,2,2,6) - assert 0 == Yahtzee.fullHouse(2,3,4,5,6) - diff --git a/Yahtzee/python/yahtzee.py b/Yahtzee/python/yahtzee.py deleted file mode 100644 index 3b6b4f15..00000000 --- a/Yahtzee/python/yahtzee.py +++ /dev/null @@ -1,230 +0,0 @@ -class Yahtzee: - - @staticmethod - def chance(d1, d2, d3, d4, d5): - total = 0 - total += d1 - total += d2 - total += d3 - total += d4 - total += d5 - return total - - @staticmethod - def yahtzee(dice): - counts = [0]*(len(dice)+1) - for die in dice: - counts[die-1] += 1 - for i in range(len(counts)): - if counts[i] == 5: - return 50 - return 0 - - @staticmethod - def ones( d1, d2, d3, d4, d5): - sum = 0 - if (d1 == 1): - sum += 1 - if (d2 == 1): - sum += 1 - if (d3 == 1): - sum += 1 - if (d4 == 1): - sum += 1 - if (d5 == 1): - sum += 1 - - return sum - - - @staticmethod - def twos( d1, d2, d3, d4, d5): - sum = 0 - if (d1 == 2): - sum += 2 - if (d2 == 2): - sum += 2 - if (d3 == 2): - sum += 2 - if (d4 == 2): - sum += 2 - if (d5 == 2): - sum += 2 - return sum - - @staticmethod - def threes( d1, d2, d3, d4, d5): - s = 0 - if (d1 == 3): - s += 3 - if (d2 == 3): - s += 3 - if (d3 == 3): - s += 3 - if (d4 == 3): - s += 3 - if (d5 == 3): - s += 3 - return s - - - def __init__(self, d1, d2, d3, d4, _5): - self.dice = [0]*5 - self.dice[0] = d1 - self.dice[1] = d2 - self.dice[2] = d3 - self.dice[3] = d4 - self.dice[4] = _5 - - def fours(self): - sum = 0 - for at in range(5): - if (self.dice[at] == 4): - sum += 4 - return sum - - - def fives(self): - s = 0 - i = 0 - for i in range(len(self.dice)): - if (self.dice[i] == 5): - s = s + 5 - return s - - - def sixes(self): - sum = 0 - for at in range(len(self.dice)): - if (self.dice[at] == 6): - sum = sum + 6 - return sum - - @staticmethod - def score_pair( d1, d2, d3, d4, d5): - counts = [0]*6 - counts[d1-1] += 1 - counts[d2-1] += 1 - counts[d3-1] += 1 - counts[d4-1] += 1 - counts[d5-1] += 1 - at = 0 - for at in range(6): - if (counts[6-at-1] == 2): - return (6-at)*2 - return 0 - - @staticmethod - def two_pair( d1, d2, d3, d4, d5): - counts = [0]*6 - counts[d1-1] += 1 - counts[d2-1] += 1 - counts[d3-1] += 1 - counts[d4-1] += 1 - counts[d5-1] += 1 - n = 0 - score = 0 - for i in range(6): - if (counts[6-i-1] == 2): - n = n+1 - score += (6-i) - - if (n == 2): - return score * 2 - else: - return 0 - - @staticmethod - def four_of_a_kind( _1, _2, d3, d4, d5): - tallies = [0]*6 - tallies[_1-1] += 1 - tallies[_2-1] += 1 - tallies[d3-1] += 1 - tallies[d4-1] += 1 - tallies[d5-1] += 1 - for i in range(6): - if (tallies[i] == 4): - return (i+1) * 4 - return 0 - - - @staticmethod - def three_of_a_kind( d1, d2, d3, d4, d5): - t = [0]*6 - t[d1-1] += 1 - t[d2-1] += 1 - t[d3-1] += 1 - t[d4-1] += 1 - t[d5-1] += 1 - for i in range(6): - if (t[i] == 3): - return (i+1) * 3 - return 0 - - - @staticmethod - def smallStraight( d1, d2, d3, d4, d5): - tallies = [0]*6 - tallies[d1-1] += 1 - tallies[d2-1] += 1 - tallies[d3-1] += 1 - tallies[d4-1] += 1 - tallies[d5-1] += 1 - if (tallies[0] == 1 and - tallies[1] == 1 and - tallies[2] == 1 and - tallies[3] == 1 and - tallies[4] == 1): - return 15 - return 0 - - - @staticmethod - def largeStraight( d1, d2, d3, d4, d5): - tallies = [0]*6 - tallies[d1-1] += 1 - tallies[d2-1] += 1 - tallies[d3-1] += 1 - tallies[d4-1] += 1 - tallies[d5-1] += 1 - if (tallies[1] == 1 and - tallies[2] == 1 and - tallies[3] == 1 and - tallies[4] == 1 - and tallies[5] == 1): - return 20 - return 0 - - - @staticmethod - def fullHouse( d1, d2, d3, d4, d5): - tallies = [] - _2 = False - i = 0 - _2_at = 0 - _3 = False - _3_at = 0 - - tallies = [0]*6 - tallies[d1-1] += 1 - tallies[d2-1] += 1 - tallies[d3-1] += 1 - tallies[d4-1] += 1 - tallies[d5-1] += 1 - - for i in range(6): - if (tallies[i] == 2): - _2 = True - _2_at = i+1 - - - for i in range(6): - if (tallies[i] == 3): - _3 = True - _3_at = i+1 - - - if (_2 and _3): - return _2_at * 2 + _3_at * 3 - else: - return 0 diff --git a/Yahtzee/ruby/test_yahtzee.rb b/Yahtzee/ruby/test_yahtzee.rb deleted file mode 100644 index 988c0f0d..00000000 --- a/Yahtzee/ruby/test_yahtzee.rb +++ /dev/null @@ -1,94 +0,0 @@ -require_relative 'yahtzee' -require 'test/unit' - -class YahtzeeTest < Test::Unit::TestCase - def test_chance_scores_sum_of_all_dice - expected = 15 - actual = Yahtzee.chance(2,3,4,5,1) - assert expected == actual - assert 16 == Yahtzee.chance(3,3,4,5,1) - end - - def test_yahtzee_scores_50 - expected = 50 - actual = Yahtzee.yahtzee([4,4,4,4,4]) - assert expected == actual - assert 50 == Yahtzee.yahtzee([6,6,6,6,6]) - assert 0 == Yahtzee.yahtzee([6,6,6,6,3]) - end - - def test_1s - assert Yahtzee.ones(1,2,3,4,5) == 1 - assert 2 == Yahtzee.ones(1,2,1,4,5) - assert 0 == Yahtzee.ones(6,2,2,4,5) - assert 4 == Yahtzee.ones(1,2,1,1,1) - end - - def test_2s - assert Yahtzee.twos(1,2,3,2,6) == 4 - assert Yahtzee.twos(2,2,2,2,2) == 10 - end - - def test_threes - assert 6 == Yahtzee.threes(1,2,3,2,3) - assert 12 == Yahtzee.threes(2,3,3,3,3) - end - - def test_fours_test - assert 12 == Yahtzee.new(4,4,4,5,5).fours - assert 8 == Yahtzee.new(4,4,5,5,5).fours - assert 4 == Yahtzee.new(4,5,5,5,5).fours - end - - def test_fives() - assert 10 == Yahtzee.new(4,4,4,5,5).fives() - assert 15 == Yahtzee.new(4,4,5,5,5).fives() - assert 20 == Yahtzee.new(4,5,5,5,5).fives() - end - - def test_sixes_test - assert 0 == Yahtzee.new(4,4,4,5,5).sixes() - assert 6 == Yahtzee.new(4,4,6,5,5).sixes() - assert 18 == Yahtzee.new(6,5,6,6,5).sixes() - end - - def test_one_pair - assert 6 == Yahtzee.score_pair(3,4,3,5,6) - assert 10 == Yahtzee.score_pair(5,3,3,3,5) - assert 12 == Yahtzee.score_pair(5,3,6,6,5) - end - - def test_two_Pair - assert_equal 16, Yahtzee.two_pair(3,3,5,4,5) - assert_equal 0, Yahtzee.two_pair(3,3,5,5,5) - end - - def test_three_of_a_kind() - assert 9 == Yahtzee.three_of_a_kind(3,3,3,4,5) - assert 15 == Yahtzee.three_of_a_kind(5,3,5,4,5) - assert 0 == Yahtzee.three_of_a_kind(3,3,3,3,5) - end - - def test_four_of_a_knd - assert 12 == Yahtzee.four_of_a_kind(3,3,3,3,5) - assert 20 == Yahtzee.four_of_a_kind(5,5,5,4,5) - assert 0 == Yahtzee.three_of_a_kind(3,3,3,3,3) - end - - def test_smallStraight() - assert 15 == Yahtzee.smallStraight(1,2,3,4,5) - assert 15 == Yahtzee.smallStraight(2,3,4,5,1) - assert 0 == Yahtzee.smallStraight(1,2,2,4,5) - end - - def test_largeStraight - assert 20 == Yahtzee.largeStraight(6,2,3,4,5) - assert 20 == Yahtzee.largeStraight(2,3,4,5,6) - assert 0 == Yahtzee.largeStraight(1,2,2,4,5) - end - - def test_fullHouse() - assert 18 == Yahtzee.fullHouse(6,2,2,2,6) - assert 0 == Yahtzee.fullHouse(2,3,4,5,6) - end -end diff --git a/Yahtzee/ruby/yahtzee.rb b/Yahtzee/ruby/yahtzee.rb deleted file mode 100644 index 462b0509..00000000 --- a/Yahtzee/ruby/yahtzee.rb +++ /dev/null @@ -1,256 +0,0 @@ -class Yahtzee - def self.chance(d1, d2, d3, d4, d5) - total = 0 - total += d1 - total += d2 - total += d3 - total += d4 - total += d5 - return total - end - - def self.yahtzee(dice) - counts = [0]*(dice.length+1) - for die in dice do - counts[die-1] += 1 - end - for i in 0..counts.size do - if counts[i] == 5 - return 50 - end - end - return 0 - end - - def self.ones( d1, d2, d3, d4, d5) - sum = 0 - if (d1 == 1) - sum += 1 - end - if (d2 == 1) - sum += 1 - end - if (d3 == 1) - sum += 1 - end - if (d4 == 1) - sum += 1 - end - if (d5 == 1) - sum += 1 - end - - sum - end - - def self.twos( d1, d2, d3, d4, d5) - sum = 0 - if (d1 == 2) - sum += 2 - end - if (d2 == 2) - sum += 2 - end - if (d3 == 2) - sum += 2 - end - if (d4 == 2) - sum += 2 - end - if (d5 == 2) - sum += 2 - end - return sum - end - - def self.threes( d1, d2, d3, d4, d5) - s = 0 - if (d1 == 3) - s += 3 - end - if (d2 == 3) - s += 3 - end - if (d3 == 3) - s += 3 - end - if (d4 == 3) - s += 3 - end - if (d5 == 3) - s += 3 - end - return s - end - - def initialize(d1, d2, d3, d4, _5) - @dice = [0]*5 - @dice[0] = d1 - @dice[1] = d2 - @dice[2] = d3 - @dice[3] = d4 - @dice[4] = _5 - end - - def fours - sum = 0 - for at in Array 0..4 - if (@dice[at] == 4) - sum += 4 - end - end - return sum - end - - def fives() - s = 0 - i = 0 - for i in (Range.new(0, @dice.size)) - if (@dice[i] == 5) - s = s + 5 - end - end - s - end - - def sixes - sum = 0 - for at in 0..@dice.length - if (@dice[at] == 6) - sum = sum + 6 - end - end - return sum - end - - def self.score_pair( d1, d2, d3, d4, d5) - counts = [0]*6 - counts[d1-1] += 1 - counts[d2-1] += 1 - counts[d3-1] += 1 - counts[d4-1] += 1 - counts[d5-1] += 1 - at = 0 - (0...6).each do |at| - if (counts[6-at-1] == 2) - return (6-at)*2 - end - end - return 0 - end - - def self.two_pair( d1, d2, d3, d4, d5) - counts = [0]*6 - counts[d1-1] += 1 - counts[d2-1] += 1 - counts[d3-1] += 1 - counts[d4-1] += 1 - counts[d5-1] += 1 - n = 0 - score = 0 - for i in Array 0..5 - if (counts[6-i-1] == 2) - n = n+1 - score += (6-i) - end - end - if (n == 2) - return score * 2 - else - return 0 - end - end - - def self.four_of_a_kind( _1, _2, d3, d4, d5) - tallies = [0]*6 - tallies[_1-1] += 1 - tallies[_2-1] += 1 - tallies[d3-1] += 1 - tallies[d4-1] += 1 - tallies[d5-1] += 1 - for i in (0..6) - if (tallies[i] == 4) - return (i+1) * 4 - end - end - return 0 - end - - def self.three_of_a_kind( d1, d2, d3, d4, d5) - t = [0]*6 - t[d1-1] += 1 - t[d2-1] += 1 - t[d3-1] += 1 - t[d4-1] += 1 - t[d5-1] += 1 - for i in [0,1,2,3,4,5] - if (t[i] == 3) - return (i+1) * 3 - end - end - 0 - end - - def self.smallStraight( d1, d2, d3, d4, d5) - tallies = [0]*6 - tallies[d1-1] += 1 - tallies[d2-1] += 1 - tallies[d3-1] += 1 - tallies[d4-1] += 1 - tallies[d5-1] += 1 - (tallies[0] == 1 and - tallies[1] == 1 and - tallies[2] == 1 and - tallies[3] == 1 and - tallies[4] == 1) ? 15 : 0 - end - - def self.largeStraight( d1, d2, d3, d4, d5) - tallies = [0]*6 - tallies[d1-1] += 1 - tallies[d2-1] += 1 - tallies[d3-1] += 1 - tallies[d4-1] += 1 - tallies[d5-1] += 1 - if (tallies[1] == 1 and tallies[2] == 1 and tallies[3] == 1 and tallies[4] == 1 and tallies[5] == 1) - return 20 - end - return 0 - end - - def self.fullHouse( d1, d2, d3, d4, d5) - tallies = [] - _2 = false - i = 0 - _2_at = 0 - _3 = false - _3_at = 0 - - tallies = [0]*6 - tallies[d1-1] += 1 - tallies[d2-1] += 1 - tallies[d3-1] += 1 - tallies[d4-1] += 1 - tallies[d5-1] += 1 - - for i in Array 0..5 - if (tallies[i] == 2) - _2 = true - _2_at = i+1 - end - end - - for i in Array 0..5 - if (tallies[i] == 3) - _3 = true - _3_at = i+1 - end - end - - if (_2 and _3) - return _2_at * 2 + _3_at * 3 - else - return 0 - end - end -end diff --git a/GildedRose/cpp/GildedRose.cc b/cpp/GildedRose.cc similarity index 100% rename from GildedRose/cpp/GildedRose.cc rename to cpp/GildedRose.cc diff --git a/GildedRose/cpp/GildedRose.h b/cpp/GildedRose.h similarity index 100% rename from GildedRose/cpp/GildedRose.h rename to cpp/GildedRose.h diff --git a/GildedRose/cpp/GildedRoseTextTests.cc b/cpp/GildedRoseTextTests.cc similarity index 100% rename from GildedRose/cpp/GildedRoseTextTests.cc rename to cpp/GildedRoseTextTests.cc diff --git a/GildedRose/cpp/GildedRoseUnitTests.cc b/cpp/GildedRoseUnitTests.cc similarity index 100% rename from GildedRose/cpp/GildedRoseUnitTests.cc rename to cpp/GildedRoseUnitTests.cc diff --git a/GildedRose/cpp/Makefile b/cpp/Makefile similarity index 100% rename from GildedRose/cpp/Makefile rename to cpp/Makefile diff --git a/GildedRose/cpp/README b/cpp/README similarity index 100% rename from GildedRose/cpp/README rename to cpp/README diff --git a/GildedRose/cpp/run-once.sh b/cpp/run-once.sh similarity index 100% rename from GildedRose/cpp/run-once.sh rename to cpp/run-once.sh diff --git a/GildedRose/csharp/ApprovalTest.cs b/csharp/ApprovalTest.cs similarity index 100% rename from GildedRose/csharp/ApprovalTest.cs rename to csharp/ApprovalTest.cs diff --git a/GildedRose/csharp/GildedRose.cs b/csharp/GildedRose.cs similarity index 100% rename from GildedRose/csharp/GildedRose.cs rename to csharp/GildedRose.cs diff --git a/GildedRose/csharp/GildedRoseTest.cs b/csharp/GildedRoseTest.cs similarity index 100% rename from GildedRose/csharp/GildedRoseTest.cs rename to csharp/GildedRoseTest.cs diff --git a/GildedRose/csharp/TextTestFixture.cs b/csharp/TextTestFixture.cs similarity index 100% rename from GildedRose/csharp/TextTestFixture.cs rename to csharp/TextTestFixture.cs diff --git a/GildedRose/js/.gitignore b/js/.gitignore similarity index 100% rename from GildedRose/js/.gitignore rename to js/.gitignore diff --git a/GildedRose/js/README.md b/js/README.md similarity index 100% rename from GildedRose/js/README.md rename to js/README.md diff --git a/GildedRose/js/SpecRunner.html b/js/SpecRunner.html similarity index 100% rename from GildedRose/js/SpecRunner.html rename to js/SpecRunner.html diff --git a/GildedRose/js/lib/jasmine-1.1.0/MIT.LICENSE b/js/lib/jasmine-1.1.0/MIT.LICENSE similarity index 100% rename from GildedRose/js/lib/jasmine-1.1.0/MIT.LICENSE rename to js/lib/jasmine-1.1.0/MIT.LICENSE diff --git a/GildedRose/js/lib/jasmine-1.1.0/jasmine-html.js b/js/lib/jasmine-1.1.0/jasmine-html.js similarity index 100% rename from GildedRose/js/lib/jasmine-1.1.0/jasmine-html.js rename to js/lib/jasmine-1.1.0/jasmine-html.js diff --git a/GildedRose/js/lib/jasmine-1.1.0/jasmine.css b/js/lib/jasmine-1.1.0/jasmine.css similarity index 100% rename from GildedRose/js/lib/jasmine-1.1.0/jasmine.css rename to js/lib/jasmine-1.1.0/jasmine.css diff --git a/GildedRose/js/lib/jasmine-1.1.0/jasmine.js b/js/lib/jasmine-1.1.0/jasmine.js similarity index 100% rename from GildedRose/js/lib/jasmine-1.1.0/jasmine.js rename to js/lib/jasmine-1.1.0/jasmine.js diff --git a/GildedRose/js/lib/jasmine-1.1.0/jasmine_favicon.png b/js/lib/jasmine-1.1.0/jasmine_favicon.png similarity index 100% rename from GildedRose/js/lib/jasmine-1.1.0/jasmine_favicon.png rename to js/lib/jasmine-1.1.0/jasmine_favicon.png diff --git a/GildedRose/js/lib/jasmine-ajax/mock-ajax.js b/js/lib/jasmine-ajax/mock-ajax.js similarity index 100% rename from GildedRose/js/lib/jasmine-ajax/mock-ajax.js rename to js/lib/jasmine-ajax/mock-ajax.js diff --git a/GildedRose/js/lib/jasmine-jquery-1.3.1/jasmine-jquery-1.3.1.js b/js/lib/jasmine-jquery-1.3.1/jasmine-jquery-1.3.1.js similarity index 100% rename from GildedRose/js/lib/jasmine-jquery-1.3.1/jasmine-jquery-1.3.1.js rename to js/lib/jasmine-jquery-1.3.1/jasmine-jquery-1.3.1.js diff --git a/GildedRose/js/lib/jquery-1.7.1/jquery-1.7.1.js b/js/lib/jquery-1.7.1/jquery-1.7.1.js similarity index 100% rename from GildedRose/js/lib/jquery-1.7.1/jquery-1.7.1.js rename to js/lib/jquery-1.7.1/jquery-1.7.1.js diff --git a/GildedRose/js/spec/gilded_rose_spec.js b/js/spec/gilded_rose_spec.js similarity index 100% rename from GildedRose/js/spec/gilded_rose_spec.js rename to js/spec/gilded_rose_spec.js diff --git a/GildedRose/js/src/gilded_rose.js b/js/src/gilded_rose.js similarity index 100% rename from GildedRose/js/src/gilded_rose.js rename to js/src/gilded_rose.js diff --git a/GildedRose/python/gilded_rose.py b/python/gilded_rose.py similarity index 100% rename from GildedRose/python/gilded_rose.py rename to python/gilded_rose.py diff --git a/GildedRose/python/test_gilded_rose.py b/python/test_gilded_rose.py similarity index 100% rename from GildedRose/python/test_gilded_rose.py rename to python/test_gilded_rose.py diff --git a/GildedRose/python/texttest_fixture.py b/python/texttest_fixture.py similarity index 100% rename from GildedRose/python/texttest_fixture.py rename to python/texttest_fixture.py diff --git a/GildedRose/ruby/.rspec b/ruby/.rspec similarity index 100% rename from GildedRose/ruby/.rspec rename to ruby/.rspec diff --git a/GildedRose/ruby/gilded_rose.rb b/ruby/gilded_rose.rb similarity index 100% rename from GildedRose/ruby/gilded_rose.rb rename to ruby/gilded_rose.rb diff --git a/GildedRose/ruby/gilded_rose_spec.rb b/ruby/gilded_rose_spec.rb similarity index 100% rename from GildedRose/ruby/gilded_rose_spec.rb rename to ruby/gilded_rose_spec.rb diff --git a/GildedRose/ruby/gilded_rose_tests.rb b/ruby/gilded_rose_tests.rb similarity index 100% rename from GildedRose/ruby/gilded_rose_tests.rb rename to ruby/gilded_rose_tests.rb diff --git a/GildedRose/ruby/texttest_fixture.rb b/ruby/texttest_fixture.rb similarity index 100% rename from GildedRose/ruby/texttest_fixture.rb rename to ruby/texttest_fixture.rb diff --git a/GildedRose/texttests/README.md b/texttests/README.md similarity index 100% rename from GildedRose/texttests/README.md rename to texttests/README.md diff --git a/GildedRose/texttests/ThirtyDays/._options.gr b/texttests/ThirtyDays/._options.gr similarity index 100% rename from GildedRose/texttests/ThirtyDays/._options.gr rename to texttests/ThirtyDays/._options.gr diff --git a/GildedRose/texttests/ThirtyDays/options.gr b/texttests/ThirtyDays/options.gr similarity index 100% rename from GildedRose/texttests/ThirtyDays/options.gr rename to texttests/ThirtyDays/options.gr diff --git a/GildedRose/texttests/ThirtyDays/stderr.gr b/texttests/ThirtyDays/stderr.gr similarity index 100% rename from GildedRose/texttests/ThirtyDays/stderr.gr rename to texttests/ThirtyDays/stderr.gr diff --git a/GildedRose/texttests/ThirtyDays/stdout.gr b/texttests/ThirtyDays/stdout.gr similarity index 100% rename from GildedRose/texttests/ThirtyDays/stdout.gr rename to texttests/ThirtyDays/stdout.gr diff --git a/GildedRose/texttests/config.gr b/texttests/config.gr similarity index 100% rename from GildedRose/texttests/config.gr rename to texttests/config.gr diff --git a/GildedRose/texttests/environment.gr b/texttests/environment.gr similarity index 100% rename from GildedRose/texttests/environment.gr rename to texttests/environment.gr diff --git a/GildedRose/texttests/testsuite.gr b/texttests/testsuite.gr similarity index 100% rename from GildedRose/texttests/testsuite.gr rename to texttests/testsuite.gr