FizzBuzzؔ
enum FizzBuzz {
static func fizzBuzz(_ number: Int) -> String {
guard number > 0 else { return "out of range” }
switch number {
case let n where n % 15 == 0: return "FizzBuzz"
case let n where n % 5 == 0: return "Buzz"
case let n where n % 3 == 0: return "Fizz"
default: return String(number)
}
}
}
Slide 12
Slide 12 text
·ͣԿߟ͑ͣʹͱΓ͋͑ͣ
ςετΛॻ͍ͯΈΔ ✍
Slide 13
Slide 13 text
ͳʹߟ͑ͣʹॻ͍ͨςετ
class FizzBuzzSpec: QuickSpec {
override func spec() {
describe("#fizzBuzz") {
it("should meet all FizzBuzz specifications") {
expect(FizzBuzz.fizzBuzz(3)).to(equal("Fizz"))
expect(FizzBuzz.fizzBuzz(5)).to(equal("Buzz"))
expect(FizzBuzz.fizzBuzz(15)).to(equal("FizzBuzz"))
expect(FizzBuzz.fizzBuzz(-1))
.to(equal(“out of range"))
expect(FizzBuzz.fizzBuzz(1)).to(equal("1"))
}
}
}
}
Slide 14
Slide 14 text
ͳʹߟ͑ͣʹॻ͍ͨςετ
class FizzBuzzSpec: QuickSpec {
override func spec() {
describe("#fizzBuzz") {
it("should meet all FizzBuzz specifications") {
expect(FizzBuzz.fizzBuzz(3)).to(equal("Fizz"))
expect(FizzBuzz.fizzBuzz(5)).to(equal("Buzz"))
expect(FizzBuzz.fizzBuzz(15)).to(equal("FizzBuzz"))
expect(FizzBuzz.fizzBuzz(-1))
.to(equal(“out of range"))
expect(FizzBuzz.fizzBuzz(1)).to(equal("1"))
}
}
}
}
ςετରͷϝιου
Slide 15
Slide 15 text
ͳʹߟ͑ͣʹॻ͍ͨςετ
class FizzBuzzSpec: QuickSpec {
override func spec() {
describe("#fizzBuzz") {
it("should meet all FizzBuzz specifications") {
expect(FizzBuzz.fizzBuzz(3)).to(equal("Fizz"))
expect(FizzBuzz.fizzBuzz(5)).to(equal("Buzz"))
expect(FizzBuzz.fizzBuzz(15)).to(equal("FizzBuzz"))
expect(FizzBuzz.fizzBuzz(-1))
.to(equal(“out of range"))
expect(FizzBuzz.fizzBuzz(1)).to(equal("1"))
}
}
}
}
ظ͞ΕΔϝιουͷ;Δ·͍
୯Ұ݅ςετ
describe("#fizzBuzz") {
it("should return Fizz when given multiples of 3") {
expect(FizzBuzz.fizzBuzz(3)).to(equal("Fizz"))
}
it("should return Buzz when given multiples of 5") {
expect(FizzBuzz.fizzBuzz(5)).to(equal("Buzz"))
}
it("should return FizzBuzz
when given multiples of both 3 and 5") {
expect(FizzBuzz.fizzBuzz(15)).to(equal("FizzBuzz"))
}
ɾ
ɾ
ɾ
Slide 29
Slide 29 text
୯Ұ݅ςετ
describe("#fizzBuzz") {
it("should return Fizz when given multiples of 3") {
expect(FizzBuzz.fizzBuzz(3)).to(equal("Fizz"))
}
it("should return Buzz when given multiples of 5") {
expect(FizzBuzz.fizzBuzz(5)).to(equal("Buzz"))
}
it("should return FizzBuzz
when given multiples of both 3 and 5") {
expect(FizzBuzz.fizzBuzz(15)).to(equal("FizzBuzz"))
}
ɾ
ɾ
ɾ
3ͷഒͷ࣌ -> “Fizz”
Slide 30
Slide 30 text
୯Ұ݅ςετ
describe("#fizzBuzz") {
it("should return Fizz when given multiples of 3") {
expect(FizzBuzz.fizzBuzz(3)).to(equal("Fizz"))
}
it("should return Buzz when given multiples of 5") {
expect(FizzBuzz.fizzBuzz(5)).to(equal("Buzz"))
}
it("should return FizzBuzz
when given multiples of both 3 and 5") {
expect(FizzBuzz.fizzBuzz(15)).to(equal("FizzBuzz"))
}
ɾ
ɾ
ɾ
5ͷഒͷ࣌ -> “Buzz”
Slide 31
Slide 31 text
୯Ұ݅ςετ
describe("#fizzBuzz") {
it("should return Fizz when given multiples of 3") {
expect(FizzBuzz.fizzBuzz(3)).to(equal("Fizz"))
}
it("should return Buzz when given multiples of 5") {
expect(FizzBuzz.fizzBuzz(5)).to(equal("Buzz"))
}
it("should return FizzBuzz
when given multiples of both 3 and 5") {
expect(FizzBuzz.fizzBuzz(15)).to(equal("FizzBuzz"))
}
ɾ
ɾ
ɾ
3ͱ5ͷެഒͷ࣌ -> “FizzBuzz”