Presentation is loading. Please wait.

Presentation is loading. Please wait.

Olve Maudal TDD in CPP 05 February 2007 (frontpage) TDD in CPP... or The Bowling Game Kata with C++ and QUnit Olve Maudal, (A 10 minutes Lightning.

Similar presentations


Presentation on theme: "Olve Maudal TDD in CPP 05 February 2007 (frontpage) TDD in CPP... or The Bowling Game Kata with C++ and QUnit Olve Maudal, (A 10 minutes Lightning."— Presentation transcript:

1 Olve Maudal TDD in CPP 05 February 2007 (frontpage) TDD in CPP... or The Bowling Game Kata with C++ and QUnit Olve Maudal, oma@pvv.org (A 10 minutes Lightning Talk @ Oslo XP Meetup February 2007)

2 Olve Maudal TDD in CPP 05 February 2007 QUnit - A very small unit test framework for C++ Key features: Feels like 50 lines of code Integrates nicely into your development environment No bells and whistles http://qunit.sourceforge.net

3 Olve Maudal TDD in CPP 05 February 2007 (picture)

4 Olve Maudal TDD in CPP 05 February 2007 Bowling Game Kata in C++ The following is a demonstration of how to do test-driven development using the our new framework for unit testing in C++. We are going to write some code for scoring a game of bowling. Since the seminal article "Engineer Notebook: An Extreme Programming Episode" published in 2001 by Robert C. Martin and Robert S. Koss: http://www.objectmentor.com/resources/articles/xpepisode.htm calculating the score for a bowling game has gained status as an advanced "Hello World" for programming languages. For any programming language out there you will find a bowling score implementation insipred by the "XP Episode". There is also a lot of derivative work from this article, some of them demonstrating how design evolves through Test-Driven Development. What you will see now is taken more or less directly out of the excellent Bowling Game Kata presentation by Robert C. Martin. http://butunclebob.com http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata http://butunclebob.com/files/downloads/Bowling%20Game%20Kata.ppt Basically the only thing I have done is to translate from Java/JUnit into C++/QUnit.

5 Olve Maudal TDD in CPP 05 February 2007 Since Uncle Bob is a nice guy... The following slides are not verbatim copies, but they are close enough to deserve a proper copyright notice... Some of the material is probably Copyright (C) 2005 by Object Mentor. Permission to use was given by Uncle Bob.... we include this page, because he asked us to do so:

6 Olve Maudal TDD in CPP 05 February 2007 The game consists of 10 frames as shown above. In each frame the player has two opportunities to knock down 10 pins. The score for the frame is the total number of pins knocked down, plus bonuses for strikes and spares. A spare is when the player knocks down all 10 pins in two tries. The bonus for that frame is the number of pins knocked down by the next roll. So in frame 3 above, the score is 10 (the total number knocked down) plus a bonus of 5 (the number of pins knocked down on the next roll.) A strike is when the player knocks down all 10 pins on his first try. The bonus for that frame is the value of the next two balls rolled. In the tenth frame a player who rolls a spare or strike is allowed to roll the extra balls to complete the frame. However no more than three balls can be rolled in tenth frame. Scoring Bowling [source: Uncle Bob]

7 Olve Maudal TDD in CPP 05 February 2007 The Requirements. Write a class named Game that has two methods: roll(pins : int) is called each time the player rolls a ball. The argument is the number of pins knocked down. score() : int is called only at the very end of the game. It returns the total score for that game. [source: Uncle Bob]

8 Olve Maudal TDD in CPP 05 February 2007 Scoring Bowling & The Requirements The game consists of 10 frames as shown above. In each frame the player has two opportunities to knock down 10 pins. The score for the frame is the total number of pins knocked down, plus bonuses for strikes and spares. A spare is when the player knocks down all 10 pins in two tries. The bonus for that frame is the number of pins knocked down by the next roll. So in frame 3 above, the score is 10 (the total number knocked down) plus a bonus of 5 (the number of pins knocked down on the next roll.) A strike is when the player knocks down all 10 pins on his first try. The bonus for that frame is the value of the next two balls rolled. In the tenth frame a player who rolls a spare or strike is allowed to roll the extra balls to complete the frame. However no more than three balls can be rolled in tenth frame. Write a class named Game that has two methods: roll(pins : int) is called each time the player rolls a ball. The argument is the number of pins knocked down. score() : int is called only at the very end of the game. It returns the total score for that game. [source: Uncle Bob]

9 Olve Maudal TDD in CPP 05 February 2007 A quick design session Clearly we need the Game class. [source: Uncle Bob]

10 Olve Maudal TDD in CPP 05 February 2007 A quick design session A game has 10 frames. [source: Uncle Bob]

11 Olve Maudal TDD in CPP 05 February 2007 A quick design session A frame has 1 or two rolls. [source: Uncle Bob]

12 Olve Maudal TDD in CPP 05 February 2007 A quick design session The tenth frame has two or three rolls. It is different from all the other frames. [source: Uncle Bob]

13 Olve Maudal TDD in CPP 05 February 2007 A quick design session The score function must iterate through all the frames, and calculate all their scores. [source: Uncle Bob]

14 Olve Maudal TDD in CPP 05 February 2007 A quick design session The score for a spare or a strike depends on the frames successor [source: Uncle Bob]

15 Olve Maudal TDD in CPP 05 February 2007 A quick design session class Game { Frame _frames[10]; public: void roll(int pins); int score(); }; class Frame { Roll _rolls[2]; public: virtual int score(); }; class TenthFrame : public Frame { Roll _extraroll; public: int score(); }; struct Roll { int pins; };

16 Olve Maudal TDD in CPP 05 February 2007 A quick design session class Game { Frame _frames[10]; public: void roll(int pins); int score(); }; class Frame { Roll _rolls[2]; public: virtual int score(); }; class TenthFrame : public Frame { Roll _extraroll; public: int score(); }; struct Roll { int pins; };

17 Olve Maudal TDD in CPP 05 February 2007 A quick design session class Game { Frame _frames[10]; public: void roll(int pins); int score(); }; class Frame { Roll _rolls[2]; public: int score(); }; class TenthFrame : public Frame { Roll _extraroll; public: int score(); }; struct Roll { int pins; }; NO, NO, NO.... we are supposed to do Test-Driven Development now

18 Olve Maudal TDD in CPP 05 February 2007 (blank)

19 Olve Maudal TDD in CPP 05 February 2007 Begin with Test-Driven Development Create a new project named BowlingGame Download QUnit from sourceforge.net Create an empty BowlingGame class Create a unit test named BowlingGameTest Set up a unit test environment mkdir BowlingGame cd BowlingGame wget http://downloads.sourceforge.net/qunit/qunit-1.0.tar.gz?use_mirror=osdn tar xzf qunit-1.0.tar.gz QUnit.hpp QUnit.cpp rm qunit-1.0.tar.gz ed BowlingGame.hpp ed BowlingGameTest.cpp ed Makefile make

20 Olve Maudal TDD in CPP 05 February 2007 The empty class (BowlingGame.hpp) // BowlingGame.hpp - a bowling score calculator class BowlingGame { };

21 Olve Maudal TDD in CPP 05 February 2007 The empty test (BowlingGameTest.cpp) // BowlingGameTest.cpp - Bowling Game Kata in C++ / QUnit #include "QUnit.hpp" #include "BowlingGame.hpp" #include #define ASSERT_TRUE(cond) ( assertTrue(cond, #cond, __FILE__, __LINE__) ) #define RUNTEST(name) {setContext(#name); name();} class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { BowlingGame g; } }; int main(int argc, char ** argv) { BowlingGameTest t; return t.execute(argc, argv); }

22 Olve Maudal TDD in CPP 05 February 2007 Set up a unit test environment (Makefile) # Makefile BowlingGameTest : BowlingGameTest.cpp BowlingGame.hpp QUnit.o g++ -o BowlingGameTest BowlingGameTest.cpp QUnit.o BowlingGameTest -v QUnit.o : QUnit.cpp QUnit.hpp g++ -c QUnit.cpp clean: rm BowlingGameTest QUnit.o

23 Olve Maudal TDD in CPP 05 February 2007 Verify the set up g++ -c QUnit.cpp g++ -o BowlingGameTest BowlingGameTest.cpp QUnit.o BowlingGameTest -v BowlingGameTest OK (0 tests, 0 errors)

24 Olve Maudal TDD in CPP 05 February 2007 The first test.

25 Olve Maudal TDD in CPP 05 February 2007 The first test. class BowlingGame { }; class BowlingGameTest : public QUnit { public: BowlingGameTest(): QUnit("BowlingGameTest") {}; void run() { BowlingGame g; } };

26 Olve Maudal TDD in CPP 05 February 2007 The first test. class BowlingGame { }; class BowlingGameTest : public QUnit { public: BowlingGameTest(): QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); } void testGutterGame() { BowlingGame g; } };

27 Olve Maudal TDD in CPP 05 February 2007 The first test. class BowlingGame { }; class BowlingGameTest : public QUnit { public: BowlingGameTest(): QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); } void testGutterGame() { BowlingGame g; } }; BowlingGameTest OK (0 tests, 0 errors)

28 Olve Maudal TDD in CPP 05 February 2007 The first test. class BowlingGame { }; class BowlingGameTest : public QUnit { public: BowlingGameTest(): QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); } void testGutterGame() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(0); } };

29 Olve Maudal TDD in CPP 05 February 2007 The first test. class BowlingGame { public: void roll(int pins) {} }; class BowlingGameTest : public QUnit { public: BowlingGameTest(): QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); } void testGutterGame() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(0); } };

30 Olve Maudal TDD in CPP 05 February 2007 The first test. class BowlingGame { public: void roll(int pins) {} }; class BowlingGameTest : public QUnit { public: BowlingGameTest(): QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); } void testGutterGame() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(0); } }; BowlingGameTest OK (0 tests, 0 errors)

31 Olve Maudal TDD in CPP 05 February 2007 The first test. class BowlingGame { public: void roll(int pins) {} }; class BowlingGameTest : public QUnit { public: BowlingGameTest(): QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); } void testGutterGame() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(0); } ASSERT_TRUE(g.score() == 0); } };

32 Olve Maudal TDD in CPP 05 February 2007 The first test. class BowlingGame { int _score; public: void roll(int pins) {} int score() { return _score; } }; class BowlingGameTest : public QUnit { public: BowlingGameTest(): QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); } void testGutterGame() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(0); } ASSERT_TRUE(g.score() == 0); } };

33 Olve Maudal TDD in CPP 05 February 2007 The first test. class BowlingGame { int _score; public: void roll(int pins) {} int score() { return _score; } }; ERROR BowlingGameTest/testGutterGame/1 BowlingGameTest.cpp:23: unittest failed: g.score() == 0 (BowlingGameTest/testGutterGame/1) BowlingGameTest FAILED (1 tests, 1 errors) class BowlingGameTest : public QUnit { public: BowlingGameTest(): QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); } void testGutterGame() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(0); } ASSERT_TRUE(g.score() == 0); } };

34 Olve Maudal TDD in CPP 05 February 2007 The first test. class BowlingGame { int _score; public: BowlingGame() : _score(0) {} void roll(int pins) {} int score() { return _score; } }; class BowlingGameTest : public QUnit { public: BowlingGameTest(): QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); } void testGutterGame() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(0); } ASSERT_TRUE(g.score() == 0); } };

35 Olve Maudal TDD in CPP 05 February 2007 The first test. class BowlingGame { int _score; public: BowlingGame() : _score(0) {} void roll(int pins) {} int score() { return _score; } }; class BowlingGameTest : public QUnit { public: BowlingGameTest(): QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); } void testGutterGame() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(0); } ASSERT_TRUE(g.score() == 0); } }; BowlingGameTest -v OK BowlingGameTest/testGutterGame/1 BowlingGameTest OK (1 tests, 0 errors)

36 Olve Maudal TDD in CPP 05 February 2007 The first test. class BowlingGame { int _score; public: BowlingGame() : _score(0) {} void roll(int pins) {} int score() { return _score; } }; class BowlingGameTest : public QUnit { public: BowlingGameTest(): QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); } void testGutterGame() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(0); } ASSERT_TRUE(g.score() == 0); } };

37 Olve Maudal TDD in CPP 05 February 2007 The Second Test

38 Olve Maudal TDD in CPP 05 February 2007 The Second Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); } void testGutterGame() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(0); } ASSERT_TRUE(g.score() == 0); } void testAllOnes() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(1); } ASSERT_TRUE(g.score() == 20); } }; class BowlingGame { int _score; public: BowlingGame() : _score(0) {} void roll(int pins) {} int score() { return _score; } };

39 Olve Maudal TDD in CPP 05 February 2007 The Second Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); } void testGutterGame() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(0); } ASSERT_TRUE(g.score() == 0); } void testAllOnes() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(1); } ASSERT_TRUE(g.score() == 20); } }; class BowlingGame { int _score; public: BowlingGame() : _score(0) {} void roll(int pins) {} int score() { return _score; } }; OK BowlingGameTest/testGutterGame/1 ERROR BowlingGameTest/testAllOnes/1 BowlingGameTest.cpp:32: unittest failed: g.score() == 20 (BowlingGameTest/testAllOnes/1) BowlingGameTest FAILED (2 tests, 1 errors)

40 Olve Maudal TDD in CPP 05 February 2007 The Second Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); } void testGutterGame() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(0); } ASSERT_TRUE(g.score() == 0); } void testAllOnes() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(1); } ASSERT_TRUE(g.score() == 20); } }; class BowlingGame { int _score; public: BowlingGame() : _score(0) {} void roll(int pins) { _score += pins; } int score() { return _score; } };

41 Olve Maudal TDD in CPP 05 February 2007 The Second Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); } void testGutterGame() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(0); } ASSERT_TRUE(g.score() == 0); } void testAllOnes() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(1); } ASSERT_TRUE(g.score() == 20); } }; class BowlingGame { int _score; public: BowlingGame() : _score(0) {} void roll(int pins) { _score += pins; } int score() { return _score; } }; BowlingGameTest -v OK BowlingGameTest/testGutterGame/1 OK BowlingGameTest/testAllOnes/1 BowlingGameTest OK (2 tests, 0 errors)

42 Olve Maudal TDD in CPP 05 February 2007 The Second Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); } void testGutterGame() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(0); } ASSERT_TRUE(g.score() == 0); } void testAllOnes() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(1); } ASSERT_TRUE(g.score() == 20); } }; class BowlingGame { int _score; public: BowlingGame() : _score(0) {} void roll(int pins) { _score += pins; } int score() { return _score; } };

43 Olve Maudal TDD in CPP 05 February 2007 The Second Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); } void testGutterGame() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(0); } ASSERT_TRUE(g.score() == 0); } void testAllOnes() { BowlingGame g; for (int i=0; i<20; ++i) { g.roll(1); } ASSERT_TRUE(g.score() == 20); } }; class BowlingGame { int _score; public: BowlingGame() : _score(0) {} void roll(int pins) { _score += pins; } int score() { return _score; } }; Perhaps we need refactoring of test code?

44 Olve Maudal TDD in CPP 05 February 2007 The Second Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_44.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Second Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

45 Olve Maudal TDD in CPP 05 February 2007 The Second Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_45.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Second Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

46 Olve Maudal TDD in CPP 05 February 2007 The Second Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_46.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Second Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

47 Olve Maudal TDD in CPP 05 February 2007 The Second Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_47.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Second Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

48 Olve Maudal TDD in CPP 05 February 2007 The Second Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_48.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Second Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

49 Olve Maudal TDD in CPP 05 February 2007 The Third Test

50 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_50.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

51 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_51.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

52 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_52.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

53 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_53.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

54 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_54.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

55 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_55.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

56 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGame { int _score; public: BowlingGame() : _score(0) {} void roll(int pins) { _score += pins; } int score() { return _score; } }; class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_56.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGame { int _score; public: BowlingGame() : _score(0) {} void roll(int pins) { _score += pins; } int score() { return _score; } }; class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

57 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_57.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

58 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_58.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

59 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_59.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

60 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_60.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

61 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_61.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

62 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_62.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

63 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_63.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

64 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_64.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

65 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_65.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

66 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_66.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

67 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_67.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

68 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_68.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

69 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_69.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

70 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_70.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

71 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_71.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

72 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_72.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); // RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

73 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_73.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

74 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_74.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

75 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_75.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

76 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_76.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

77 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_77.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

78 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_78.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

79 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_79.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

80 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_80.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

81 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_81.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

82 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_82.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

83 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_83.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

84 Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit("BowlingGameTest") {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_84.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Third Test class BowlingGameTest : public QUnit { public: BowlingGameTest() : QUnit( BowlingGameTest ) {}; void run() { RUNTEST(testGutterGame); RUNTEST(testAllOnes); RUNTEST(testOneSpare); } void rollMany(BowlingGame& g, int n, int pins) { for (int i=0; i

85 Olve Maudal TDD in CPP 05 February 2007 The Fourth Test

86 Olve Maudal TDD in CPP 05 February 2007 The Fourth Test //... void testOneSpare() { BowlingGame g; g.roll(5); g.roll(5); // spare g.roll(3); rollMany(g, 17, 0); ASSERT_TRUE(g.score() == 16); } void testOneStrike() { BowlingGame g; g.roll(10); // strike g.roll(3); g.roll(4); rollMany(g, 16, 0); ASSERT_TRUE(g.score() == 24); } //... class BowlingGame { const static int MAX_ROLLS = 21; int _rolls[MAX_ROLLS]; int _currentRoll; bool isSpare(int frameIndex) { return _rolls[frameIndex] + _rolls[frameIndex+1] == 10; } public: BowlingGame() : _currentRoll(0) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_86.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Fourth Test //...", "description": "void testOneSpare() { BowlingGame g; g.roll(5); g.roll(5); // spare g.roll(3); rollMany(g, 17, 0); ASSERT_TRUE(g.score() == 16); } void testOneStrike() { BowlingGame g; g.roll(10); // strike g.roll(3); g.roll(4); rollMany(g, 16, 0); ASSERT_TRUE(g.score() == 24); } //... class BowlingGame { const static int MAX_ROLLS = 21; int _rolls[MAX_ROLLS]; int _currentRoll; bool isSpare(int frameIndex) { return _rolls[frameIndex] + _rolls[frameIndex+1] == 10; } public: BowlingGame() : _currentRoll(0) { for (int i=0; i

87 Olve Maudal TDD in CPP 05 February 2007 The Fourth Test //... void testOneSpare() { BowlingGame g; g.roll(5); g.roll(5); // spare g.roll(3); rollMany(g, 17, 0); ASSERT_TRUE(g.score() == 16); } void testOneStrike() { BowlingGame g; g.roll(10); // strike g.roll(3); g.roll(4); rollMany(g, 16, 0); ASSERT_TRUE(g.score() == 24); } //... class BowlingGame { const static int MAX_ROLLS = 21; int _rolls[MAX_ROLLS]; int _currentRoll; bool isSpare(int frameIndex) { return _rolls[frameIndex] + _rolls[frameIndex+1] == 10; } public: BowlingGame() : _currentRoll(0) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_87.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Fourth Test //...", "description": "void testOneSpare() { BowlingGame g; g.roll(5); g.roll(5); // spare g.roll(3); rollMany(g, 17, 0); ASSERT_TRUE(g.score() == 16); } void testOneStrike() { BowlingGame g; g.roll(10); // strike g.roll(3); g.roll(4); rollMany(g, 16, 0); ASSERT_TRUE(g.score() == 24); } //... class BowlingGame { const static int MAX_ROLLS = 21; int _rolls[MAX_ROLLS]; int _currentRoll; bool isSpare(int frameIndex) { return _rolls[frameIndex] + _rolls[frameIndex+1] == 10; } public: BowlingGame() : _currentRoll(0) { for (int i=0; i

88 Olve Maudal TDD in CPP 05 February 2007 The Fourth Test //... void testOneSpare() { BowlingGame g; g.roll(5); g.roll(5); // spare g.roll(3); rollMany(g, 17, 0); ASSERT_TRUE(g.score() == 16); } void testOneStrike() { BowlingGame g; g.roll(10); // strike g.roll(3); g.roll(4); rollMany(g, 16, 0); ASSERT_TRUE(g.score() == 24); } //... class BowlingGame { const static int MAX_ROLLS = 21; int _rolls[MAX_ROLLS]; int _currentRoll; bool isSpare(int frameIndex) { return _rolls[frameIndex] + _rolls[frameIndex+1] == 10; } bool isStrike(int frameIndex) { return _rolls[frameIndex] == 10; } public: BowlingGame() : _currentRoll(0) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_88.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Fourth Test //...", "description": "void testOneSpare() { BowlingGame g; g.roll(5); g.roll(5); // spare g.roll(3); rollMany(g, 17, 0); ASSERT_TRUE(g.score() == 16); } void testOneStrike() { BowlingGame g; g.roll(10); // strike g.roll(3); g.roll(4); rollMany(g, 16, 0); ASSERT_TRUE(g.score() == 24); } //... class BowlingGame { const static int MAX_ROLLS = 21; int _rolls[MAX_ROLLS]; int _currentRoll; bool isSpare(int frameIndex) { return _rolls[frameIndex] + _rolls[frameIndex+1] == 10; } bool isStrike(int frameIndex) { return _rolls[frameIndex] == 10; } public: BowlingGame() : _currentRoll(0) { for (int i=0; i

89 Olve Maudal TDD in CPP 05 February 2007 The Fourth Test //... void testOneSpare() { BowlingGame g; g.roll(5); g.roll(5); // spare g.roll(3); rollMany(g, 17, 0); ASSERT_TRUE(g.score() == 16); } void testOneStrike() { BowlingGame g; g.roll(10); // strike g.roll(3); g.roll(4); rollMany(g, 16, 0); ASSERT_TRUE(g.score() == 24); } //... class BowlingGame { const static int MAX_ROLLS = 21; int _rolls[MAX_ROLLS]; int _currentRoll; bool isSpare(int frameIndex) { return _rolls[frameIndex] + _rolls[frameIndex+1] == 10; } bool isStrike(int frameIndex) { return _rolls[frameIndex] == 10; } public: BowlingGame() : _currentRoll(0) { for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/1/257992/slides/slide_89.jpg", "name": "Olve Maudal TDD in CPP 05 February 2007 The Fourth Test //...", "description": "void testOneSpare() { BowlingGame g; g.roll(5); g.roll(5); // spare g.roll(3); rollMany(g, 17, 0); ASSERT_TRUE(g.score() == 16); } void testOneStrike() { BowlingGame g; g.roll(10); // strike g.roll(3); g.roll(4); rollMany(g, 16, 0); ASSERT_TRUE(g.score() == 24); } //... class BowlingGame { const static int MAX_ROLLS = 21; int _rolls[MAX_ROLLS]; int _currentRoll; bool isSpare(int frameIndex) { return _rolls[frameIndex] + _rolls[frameIndex+1] == 10; } bool isStrike(int frameIndex) { return _rolls[frameIndex] == 10; } public: BowlingGame() : _currentRoll(0) { for (int i=0; i

90 Olve Maudal TDD in CPP 05 February 2007 The Fourth Test //... void testOneSpare() { BowlingGame g; g.roll(5); g.roll(5); // spare g.roll(3); rollMany(g, 17, 0); ASSERT_TRUE(g.score() == 16); } void testOneStrike() { BowlingGame g; g.roll(10); // strike g.roll(3); g.roll(4); rollMany(g, 16, 0); ASSERT_TRUE(g.score() == 24); } //... private: bool isSpare(int frameIndex) { return _rolls[frameIndex] + _rolls[frameIndex+1] == 10; } bool isStrike(int frameIndex) { return _rolls[frameIndex] == 10; } int strikeBonus(int frameIndex) { return _rolls[frameIndex+1] + _rolls[frameIndex+2]; } int spareBonus(int frameIndex) { return _rolls[frameIndex+2]; } int sumOfRollsInFrame(int frameIndex) { return _rolls[frameIndex] + _rolls[frameIndex+1]; } public: //... int score() { int score = 0; int frameIndex = 0; for (int frame=0; frame<10; ++frame) { if ( isStrike(frameIndex) ) { score += 10 + strikeBonus(frameIndex); frameIndex += 1; } else if ( isSpare(frameIndex) ) { score += 10 + spareBonus(frameIndex); frameIndex += 2; } else { score += sumOfRollsInFrame(frameIndex); frameIndex += 2; } return score; }

91 Olve Maudal TDD in CPP 05 February 2007 The Fourth Test //... void testOneSpare() { BowlingGame g; g.roll(5); g.roll(5); // spare g.roll(3); rollMany(g, 17, 0); ASSERT_TRUE(g.score() == 16); } void testOneStrike() { BowlingGame g; g.roll(10); // strike g.roll(3); g.roll(4); rollMany(g, 16, 0); ASSERT_TRUE(g.score() == 24); } //... private: bool isSpare(int frameIndex) { return _rolls[frameIndex] + _rolls[frameIndex+1] == 10; } bool isStrike(int frameIndex) { return _rolls[frameIndex] == 10; } int strikeBonus(int frameIndex) { return _rolls[frameIndex+1] + _rolls[frameIndex+2]; } int spareBonus(int frameIndex) { return _rolls[frameIndex+2]; } int sumOfRollsInFrame(int frameIndex) { return _rolls[frameIndex] + _rolls[frameIndex+1]; } public: //... int score() { int score = 0; int frameIndex = 0; for (int frame=0; frame<10; ++frame) { if ( isStrike(frameIndex) ) { score += 10 + strikeBonus(frameIndex); frameIndex += 1; } else if ( isSpare(frameIndex) ) { score += 10 + spareBonus(frameIndex); frameIndex += 2; } else { score += sumOfRollsInFrame(frameIndex); frameIndex += 2; } return score; }

92 Olve Maudal TDD in CPP 05 February 2007 The Fourth Test //... void testOneSpare() { BowlingGame g; g.roll(5); g.roll(5); // spare g.roll(3); rollMany(g, 17, 0); ASSERT_TRUE(g.score() == 16); } void testOneStrike() { BowlingGame g; g.roll(10); // strike g.roll(3); g.roll(4); rollMany(g, 16, 0); ASSERT_TRUE(g.score() == 24); } //... private: bool isSpare(int frameIndex) { return _rolls[frameIndex] + _rolls[frameIndex+1] == 10; } bool isStrike(int frameIndex) { return _rolls[frameIndex] == 10; } int strikeBonus(int frameIndex) { return _rolls[frameIndex+1] + _rolls[frameIndex+2]; } int spareBonus(int frameIndex) { return _rolls[frameIndex+2]; } int sumOfRollsInFrame(int frameIndex) { return _rolls[frameIndex] + _rolls[frameIndex+1]; } public: //... int score() { int score = 0; int frameIndex = 0; for (int frame=0; frame<10; ++frame) { if ( isStrike(frameIndex) ) { score += 10 + strikeBonus(frameIndex); frameIndex += 1; } else if ( isSpare(frameIndex) ) { score += 10 + spareBonus(frameIndex); frameIndex += 2; } else { score += sumOfRollsInFrame(frameIndex); frameIndex += 2; } return score; }

93 Olve Maudal TDD in CPP 05 February 2007 The Fifth Test

94 Olve Maudal TDD in CPP 05 February 2007 The Fifth Test //... void testOneSpare() { BowlingGame g; g.roll(5); g.roll(5); // spare g.roll(3); rollMany(g, 17, 0); ASSERT_TRUE(g.score() == 16); } void testOneStrike() { BowlingGame g; g.roll(10); // strike g.roll(3); g.roll(4); rollMany(g, 16, 0); ASSERT_TRUE(g.score() == 24); } void testPerfectGame() { BowlingGame g; rollMany(g, 12, 10); ASSERT_TRUE(g.score() == 300); } //... int score() { int score = 0; int frameIndex = 0; for (int frame=0; frame<10; ++frame) { if ( isStrike(frameIndex) ) { score += 10 + strikeBonus(frameIndex); frameIndex += 1; } else if ( isSpare(frameIndex) ) { score += 10 + spareBonus(frameIndex); frameIndex += 2; } else { score += sumOfRollsInFrame(frameIndex); frameIndex += 2; } return score; }

95 Olve Maudal TDD in CPP 05 February 2007 The Fifth Test //... void testOneSpare() { BowlingGame g; g.roll(5); g.roll(5); // spare g.roll(3); rollMany(g, 17, 0); ASSERT_TRUE(g.score() == 16); } void testOneStrike() { BowlingGame g; g.roll(10); // strike g.roll(3); g.roll(4); rollMany(g, 16, 0); ASSERT_TRUE(g.score() == 24); } void testPerfectGame() { BowlingGame g; rollMany(g, 12, 10); ASSERT_TRUE(g.score() == 300); } //... int score() { int score = 0; int frameIndex = 0; for (int frame=0; frame<10; ++frame) { if ( isStrike(frameIndex) ) { score += 10 + strikeBonus(frameIndex); frameIndex += 1; } else if ( isSpare(frameIndex) ) { score += 10 + spareBonus(frameIndex); frameIndex += 2; } else { score += sumOfRollsInFrame(frameIndex); frameIndex += 2; } return score; } OK BowlingGameTest/testGutterGame/1 OK BowlingGameTest/testAllOnes/1 OK BowlingGameTest/testOneSpare/1 OK BowlingGameTest/testOneStrike/1 OK BowlingGameTest/testPerfectGame/1 BowlingGameTest OK (5 tests, 0 errors)

96 Olve Maudal TDD in CPP 05 February 2007 The Fifth Test //... void testOneSpare() { BowlingGame g; g.roll(5); g.roll(5); // spare g.roll(3); rollMany(g, 17, 0); ASSERT_TRUE(g.score() == 16); } void testOneStrike() { BowlingGame g; g.roll(10); // strike g.roll(3); g.roll(4); rollMany(g, 16, 0); ASSERT_TRUE(g.score() == 24); } void testPerfectGame() { BowlingGame g; rollMany(g, 12, 10); ASSERT_TRUE(g.score() == 300); } //... int score() { int score = 0; int frameIndex = 0; for (int frame=0; frame<10; ++frame) { if ( isStrike(frameIndex) ) { score += 10 + strikeBonus(frameIndex); frameIndex += 1; } else if ( isSpare(frameIndex) ) { score += 10 + spareBonus(frameIndex); frameIndex += 2; } else { score += sumOfRollsInFrame(frameIndex); frameIndex += 2; } return score; }

97 Olve Maudal TDD in CPP 05 February 2007 Comparing TDD and OOAD Design by TDDDesign by OOAD

98 Olve Maudal TDD in CPP 05 February 2007 Comparing TDD and OOAD Design by TDDDesign by OOAD (ok, this design is not good... but it illustrates the point well)

99 Olve Maudal TDD in CPP 05 February 2007 (blank)


Download ppt "Olve Maudal TDD in CPP 05 February 2007 (frontpage) TDD in CPP... or The Bowling Game Kata with C++ and QUnit Olve Maudal, (A 10 minutes Lightning."

Similar presentations


Ads by Google