LoginSignup
0
0

More than 1 year has passed since last update.

SwiftでTDD写経 第三章 三角測量

Posted at

注意:TDD勉強会会用の資料です。
殴り書きしてあとで清書していくので投稿段階では綺麗ではありません。

playground.swift
var money = MoneyTest()

money.TestMultiplication()
money.TestEquality()
class MoneyTest{
    init(){}
    
    func TestMultiplication(){
        var five = Dollar(5)
        var Product:Dollar = five.times(2);
        print(Product.amount)
        Product = five.times(3);
        print(Product.amount)
    }

    func TestEquality(){
        assert(Dollar(5).equals(Dollar(5)))
        assert(Dollar(6).equals(Dollar(6)))
    }
}

class Dollar  {

    var amount:Int
    
    init(_ amount:Int){
        self.amount = amount
    }
    
    func times(_ multiplire:Int)  -> Dollar{
        return Dollar(self.amount * multiplire)
    }
    
    func equals(_ Object:Any) -> Bool{
    var dollar:Self = Object as! Self
        return dollar.amount == self.amount
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0