// Copyright (C) 2015 About Objects, Inc. All Rights Reserved.
// See LICENSE.txt for this example's licensing information.
//
import XCTest

extension Person
{
    convenience init(_ firstName: String, _ lastName: String, _ friendID: Int) {
        self.init(firstName: firstName, lastName: lastName)
        self.friendID = friendID
    }
}

// Note: we need to specify the array type here because otherwise the
// Swift runtime doesn't see the type [Persons] as a match for [Friendable].
//
let persons = [
    Person("Fred", "Smith", 101),
    Person("Jan", "Wood", 102),
    Person("Bill", "Jones", 103),
    Person("Bob", "Hill", 104),
    Person("Dee", "Smith", 105),
    Person("Jean", "Hill", 106),
    Person("Dick", "Gray", 107),
    Person("Jill", "Ross", 108),
]

class Lab3Tests: XCTestCase
{
    func testOptionals() {
        let s1: Optional<String> = "Foo"
        print(s1)
        
        let s2: String? = "Bar"
        print(s2)
        
        let s3: String? = nil
        print (s3)
    }
    
    func testLikes() {
        let fred: Person = persons[0]
        fred.like()
        print(fred)
        fred.like()
        print(fred)
        fred.unlike()
        print(fred)
        fred.unlike()
        print(fred)
        fred.unlike()
        print(fred)
    }
    
    func testFilter()
    {
        let oldFriend = persons[5]
        let filteredPeople = persons.filter { (currPerson) -> Bool in
            currPerson.friendID == oldFriend.friendID
        }
        print(filteredPeople)
    }
    
    func testUnfriend() {
        let fred = Person(firstName: "Fred", lastName: "Smith")
        
        for currFriend in persons {
            fred.friend(currFriend)
        }
        
        print(fred.friends)
        print(fred.friends.count)
        
        fred.unfriend(fred.friends[2])
        
        print(fred.friends)
        print(fred.friends.count)
    }
    
    func testEquatable() {
        let p1 = Person("Fred", "Smith", 100)
        let p2 = Person("Fred", "Smith", 100)
        let p3 = Person("Fred", "Smith", 99)
        
        print("p1 == p1 is \(p1 == p1)")
        print("p1 == p2 is \(p1 == p2)")
        print("p1 == p3 is \(p1 == p3)")

        print("p1 === p1 is \(p1 === p1)")
        print("p1 === p2 is \(p1 === p2)")
        
        print("p1 != p2 is \(p1 != p2)")
        print("p1 != p3 is \(p1 != p3)")
    }
}
