Giter Club home page Giter Club logo

gollum's Introduction

Gollum

A Swift A/B testing framework for iOS

Build Status codecov.io Code Climate

A/B testing (also known as split testing) is a good practice to test new concepts. Gollum is a A/B testing framework easy to use and inspired on some best practices in Swift, like:

  • Value Types (structs and enums)
  • Error Handling (ErrorType and throws)
  • Compile time feedback

Instalation (Cocoapods)

Add to your Podfile:

pod 'Gollum'

Then run the command below:

$ pod install

Usage

Create a enum with Version type for your A/B test. Pass on each case a string with version name (e.g. A) and its probability (e.g. 0.5), both separated by :.

enum MyABTest: Version {
    case A = "A:0.5"
    case B = "B:0.5"
}

Register the test's cases in Gollum:

try Gollum.instance.registerVersions([MyABTest.A, MyABTest.B])

After registration, you can check which version was selected using getSelectedVersion:

switch try! Gollum.instance.getSelectedVersion(MyAdorableABTest) {
case .A:
    view.backgroundColor = UIColor.redColor()
case .B:
    view.backgroundColor = UIColor.greenColor()
}

Or using isVersionSelected:

if try! Gollum.instance.isVersionSelected(MyAdorableABTest.A) {
    view.backgroundColor = UIColor.redColor()
} else if try! Gollum.instance.isVersionSelected(MyAdorableABTest.B) {
    view.backgroundColor = UIColor.greenColor()
}

Error Handling

To avoid unexpected scenarios during an A/B testing, it's important treat errors. Gollum can throw these errors:

public enum GollumError: ErrorType {
    case VersionSyntaxError(String)
    case ProbabilitySumIncorrect(String)
    case EmptyVersionArrayPassed(String)
    case SelectedVersionNotFound(String)
}

If an A/B testing enum is created with wrong syntax, like missing version name or probability, the application will crash with error VersionSyntaxError:

enum MyABTest: Version {
    case A = ":0.5"
    case B = "B:0.5"
}

Error message:

fatal error: 'try!' expression unexpectedly raised an error: Gollum.GollumError.VersionSyntaxError("ABTest case expression must have name and probability values splitted by : (e.g. \"MyTestCaseA:0.5\")")

During an A/B test registration, the method registerVersions can throws EmptyVersionArrayPassed, SelectedVersionNotFound or ProbabilitySumIncorrect errors.

Also methods getSelectedVersion and isVersionSelected can throw SelectedVersionNotFound error.

Objective-C

Because of some Swift's features, Gollum doesn't work in Objective-C.

License

Gollum is available under the MIT license. See the LICENSE file for more info.

gollum's People

Contributors

barbosa avatar eduardoeof avatar

Watchers

 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.