GithubHelp home page GithubHelp logo

nltquickcheck's Introduction

NLTQucikCheck

like Haskell QuickCheck in Objective-C.

Feature

QucikCheck is random test library. It generate random values, and run many test cases with the values. Let's start Data Driven Testing.

How to install

CocoaPods

dependency 'NLTQuickCheck'

Usage

BDD style (Kiwi)

describe(@"QuickCheck", ^{
    it(@"BDD style example", ^{
        NLTQTestable *testable = [NLTQTestable testableWithPropertyBlockArguments2:^BOOL(id argA, id argB) {
            return [Math add:[argA intValue] b:[argB intValue]] == [argA intValue] + [argB intValue];
        } arbitraries:[NSNumber intArbitrary], [NSNumber intArbitrary], nil];
        [testable check];
        [[theValue([testable success]) should] beYes];
        NSLog(@"%@", [testable prettyReport]);
    });
});
// Tests: 100
//   ✓ Successes	: 100
//   ✗ Failures	    : 0
//   ✷ Exceptions	: 0

xUnit style (OCUnit)

- (BOOL)propAdd:(NSNumber*)a b:(NSNumber*)b {
    return [Math add:[a intValue] b:[b intValue]] == [a intValue] + [b intValue];
}
- (void)testQuickCheckXUnitStyleExample {
    NLTQTestable *testable = [NLTQTestable testableWithPropertySelector:@selector(propAdd:b:) 
                                                                 target:self
                                                            arbitraries:[NSNumber intArbitrary], [NSNumber intArbitrary], nil];
    [testable check];
    STAssertTrue([testable success], @"%@", [testable prettyReport]);
}
// Tests: 100
//   ✓ Successes	: 100
//   ✗ Failures	    : 0
//   ✷ Exceptions	: 0

Failure (Exception) Case

it(@"failure case", ^{
    NLTQTestable *testable = [NLTQTestable testableWithPropertyBlockArguments2:^BOOL(id argA, id argB) {
        return [argA intValue] - [argB intValue] > 0;
    } arbitraries:[NSNumber intArbitrary], [NSNumber intArbitrary], nil];
    [testable verboseCheck];
    [[theValue([testable success]) should] beYes];
    NSLog(@"%@", [testable prettyReport]);  
});
//Tests: 100
//  ✓ Successes	: 29
//  ✗ Failures  : 71
//    ✗ Failure  : ( 0 , 0 )
//    ✗ Failure  : ( 0 , 0 )
//    ✗ Failure  : ( 0 , 0 )
//    ✗ Failure  : ( -38 , 51 )
//    ✗ Failure  : ( -38 , 51 )
//    ✗ Failure  : ( -38 , 51 )
//    ✗ Failure  : ( -102 , 94 )
//    ✗ Failure  : ( -102 , 94 )
//    ✗ Failure  : ( -102 , 94 )
//    ✗ Failure  : ( 206 , 502 )
//    ....
//    ✗ Failure  : ( -8537 , 26611 )
//  ✷ Exceptions: 0

Default Arbitraries

NSString

  • [NSString arbitary]
  • [NSString alphabetStringArbitrary]

NSNumber

  • [NSNumber intArbitrary]
  • [NSNumber nonZeroIntArbitrary]
  • [NSNumber doubleArbitrary]
  • [NSNumber boolArbitrary]

License

MIT

nltquickcheck's People

Contributors

yaakaito avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.