---
# System prepended metadata

title: Unit Test 활동학습

---

# Unit Test 활동학습

## isValidLottoNumbers(of:)
```swift
func test_입력된숫자가6개가_아닐때_False이다() {
    // given
    let input1 = [1, 2, 3, 4, 5, 6, 7]
    let input2 = [1, 2, 3, 4, 5]
    let expectation = false
    
    // when
    let result1 = sut.isValidLottoNumbers(of: input1)
    let result2 = sut.isValidLottoNumbers(of: input2)
    
    // then
    XCTAssertEqual(result1, expectation)
    XCTAssertEqual(result2, expectation)
}


func test_배열안의숫자가_중복값을포함해서6개라면_False이다() {
    // given
    let input = [1, 2, 3, 3, 4, 5]
    let expectation = false
    
    // when
    let result = sut.isValidLottoNumbers(of: input)
    
    // then 
    XCTAssertEqual(result, expectation)
}

func test_배열안의숫자가_1에서45사이에_포함되지않으면_False이다() {
    // given
    let input1 = [0, 1, 2, 3, 4, 5]
    let input2 = [1, 2, 3, 4, 5, 46]
    let expectation = false
    
    // when
    let result1 = sut.isValidLottoNumbers(of: input1)
    let result2 = sut.isValidLottoNumbers(of: input2)
    
    // then
    XCTAssertEqual(result1, false)
    XCTAssertEqual(result2, false)
}


func test_6개의숫자가_모두1부터45사이의숫자일경우_True이다() {
    // given
    let input = [1, 3, 10, 20, 30, 45]
    let expectation = true
    
    // when
    let result = sut.isValidLottoNumbers(of: input)
    
    // then
    XCTAssertEqual(result, expectation)
}
```

<br/>

## makeRandomLottoNumberArray()
```swift
func test_반환값배열이_유효한값이면_True이다() {
    // given
    let randomNumbers = sut.makeRandomLottoNumberArray()
    let expectation = true
    
    // when
    let result = sut.isValidLottoNumbers(of: randomNumbers)
    
    // then
    XCTAssertEqual(result, expectation)
}

```

<br/>

## countMatchingNumber(user:winner:)
```swift
func test_user의로또숫자가_유효하지않다면_invalidNumbers에러를던진다() {
    // when
    let userNumbers = [1, 2, 3, 4, 5, 46]
    let winnerNumbers = [1, 2, 3, 4, 5, 6]
    let expectation = LottoMachineError.invalidNumbers
    let result = LottoMachineError?
    
    // when
    XCTAssertThrowsError(
        try sut.countMatchingNumber(user: userNumbers,
                                    winner: winnerNumbers)){ result = $0 }
    
    // then
    XCTAssertEqual(result, expectation)
}

func test_winner로또숫자가_유효하지않다면_invalidNumbers에러를던진다() {
    // given
    let userNumbers = [1, 2, 3, 4, 5, 6]
    let winnerNumbers = [1, 2, 3, 4, 5, 46]
    let expectation = LottoMachineError.invalidNumbers
    let result = LottoMachineError?
    
    // when
    XCTAssertThrowsError(
        try sut.countMatchingNumber(user: userNumbers, 
                                    winner: winnerNumbers)) { result = $0 }
    
    // then
    XCTAssertEqual(result, expectation)
}

func test_user와winner로또숫자가_유효할때_겹치는번호의개수를전달한다() {
    // given
    let userNumbers = [1, 2, 3, 4, 5, 6]
    let winnerNumbers = [4, 5, 6, 7, 8, 9]
    let expectation = 3
    
    // when
    let result = sut.countMatchingNumber(user:userNumbers, winner:winnerNumbers)
    
    // then
    XCTAssertEqual(try sut.countMatchingNumber(user:userNumbers, winner:winnerNumbers), expectation)
}
```