Skip to content

Commit

Permalink
Renamed the factorial test. Minor modifications to lemon.
Browse files Browse the repository at this point in the history
  • Loading branch information
etscrivner committed Feb 24, 2010
1 parent 84a9ce0 commit 82c7a28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
25 changes: 11 additions & 14 deletions examples/lemon_example_one.cpp → examples/factorial_test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////////////////////////
// Lemon Example One: A Simple Factorial Function
//
// Time-stamp: <Last modified 2010-02-23 02:58:43 by Eric Scrivner>
// Time-stamp: <Last modified 2010-02-23 19:42:31 by Eric Scrivner>
//
// Description:
// Provides a set of unit-tests using Lemon for a simple factorial function.
Expand All @@ -13,7 +13,7 @@
//
// Computes the factorial of the given number
int factorial(int n) {
if (n < 2) return 1;
if (n <= 0) return 1;

int result = 1;
while (n > 1) {
Expand All @@ -26,22 +26,19 @@ int factorial(int n) {

int main(int argc, char* argv[]) {
// Setup lemon for 5 tests
Lemon lemon(5);
Lemon lemon(4);

// Test 1: The factorial function handles negative numbers as expected
lemon.is(factorial(-5), 1, "(-5)! = 1");
// Test 1: Factorial of zero is one
lemon.is(factorial(0), 1, "0! = 1");

// Test 2: Factorial of zero is one
lemon.is(factorial(0), 1, "0! = 1");
// Test 2: 3! = 3 * 2 * 1
lemon.is(factorial(3), 3 * 2 * 1, "3! = 3 * 2 * 1");

// Test 3: Factorial of one is one
lemon.is(factorial(1), 1, "1! = 1");
// Test 3: (-5)! = 1
lemon.is(factorial(-5), 1, "(-5)! = 1");

// Test 4: Factorial of 2 is 2
lemon.is(factorial(2), 2, "2! = 2");

// Test 5: Factorial of 5 is 120
lemon.is(factorial(5), 120, "5! = 120");
// Test 4: 5! = 120
lemon.is(factorial(5), 120, "5! = 120");

// Finish testing and display statistics
lemon.end();
Expand Down
12 changes: 6 additions & 6 deletions lemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Lemon Unit Test Framework
// Author: Eric Scrivner
//
// Time-stamp: <Last modified 2010-02-23 03:03:23 by Eric Scrivner>
// Time-stamp: <Last modified 2010-02-23 17:12:05 by Eric Scrivner>
//
// Description:
// A lightweight, minimal unit-testing framework based on Perl Test::More
Expand All @@ -29,7 +29,7 @@ class Lemon
// This simply lets lemon know how many tests you're planning to run so that
// it can properly output the diagnostic information and doesn't have to
// count by hand (which can be tricky as one test can have many assertions).
Lemon(unsigned int num_planned_tests)
Lemon (unsigned int num_planned_tests)
: num_tests_(0),
test_number_(0),
num_skipped_(0),
Expand All @@ -44,7 +44,7 @@ class Lemon
// Signifies the end of the testing phase and prints the results.
//
// Returns true if all unskipped tests passed, false if there were failures.
bool end() {
bool end () {
// If any tests were skipped
if (num_skipped_ > 0) {
// Display information about the skipped tests
Expand Down Expand Up @@ -72,7 +72,7 @@ class Lemon
// message - A string to be written out to the display
//
// Used to display diagnostic information which is not a unit test.
void diag(const std::string& message) {
void diag (const std::string& message) {
std::cout << "# " << message << std::endl;
}

Expand All @@ -85,7 +85,7 @@ class Lemon
//
// Marks this test as passed if pass is true. The test is marked as
// failing otherwise.
bool ok(bool passed, const std::string& test_name) {
bool ok (bool passed, const std::string& test_name) {
// Increment the number of tests run
num_tests_++;

Expand Down Expand Up @@ -120,7 +120,7 @@ class Lemon
//
// Marks this test as passed if the boolean parameter is false. The test is
// marked as failing otherwise.
bool not_ok(bool failed, const std::string& test_name) {
bool not_ok (bool failed, const std::string& test_name) {
return ok(!failed, test_name);
}

Expand Down

0 comments on commit 82c7a28

Please sign in to comment.