Created
August 2, 2015 05:58
-
-
Save GE-N/b39c6daac9fff269440c to your computer and use it in GitHub Desktop.
Validate all pass - BDD on Swift @Medium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Phone class part | |
// Phone.swift | |
import Foundation | |
class Phone { | |
class func validateNumber(number: String) -> Bool { | |
// begin with 08 or 09 | |
let beginValid = number.hasPrefix("08") || number.hasPrefix("09") | |
// length = 10 | |
let lenghtValid = (count(number) == 10) | |
return beginValid && lenghtValid | |
} | |
} | |
// ==================================================================================== | |
// Test Phone part | |
// PhoneNumberSpec.swift | |
import Quick | |
import Nimble | |
import SMSME | |
class PhoneNumberSpec : QuickSpec { | |
override func spec() { | |
describe("Phone number") { | |
context("Validate") { | |
it("should length equal 10 digit") { | |
expect(Phone.validateNumber("12345")).to(beFalse()) | |
expect(Phone.validateNumber("1234567890")).to(beFalse()) | |
expect(Phone.validateNumber("0811122222")).to(beTrue()) | |
} | |
it("should begins with 08/09") { | |
expect(Phone.validateNumber("998876")).to(beFalse()) | |
expect(Phone.validateNumber("081122")).to(beFalse()) | |
expect(Phone.validateNumber("0811122222")).to(beTrue()) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment