Skip to content

Conversation

@H0sungKim
Copy link
Collaborator

저는 CalculateState enum을 배열에 보관하는 식으로 계산기 구현했습니다.

enum CalculateState {
    enum Operator {
        case add
        case subtract
        case multiply
        case divide
        case modular
    }
    case num(Int)
    case `operator`(Operator)
final class CalculatorViewModel: ObservableObject {
    
    @Published var stack: [CalculateState] = []

로직은 좀 더럽게 짰습니다.

테스트는 총 5개 만들었는데

    func test_십일더하기육() throws {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        // Any test you write for XCTest can be annotated as throws and async.
        // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
        // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
        
        sut.buttonTapped(.one)
        sut.buttonTapped(.one)
        sut.buttonTapped(.add)
        sut.buttonTapped(.six)
        sut.buttonTapped(.equal)
        
        XCTAssertEqual(sut.stack.map(\.text).joined(separator: " "), "17")
    }
    
    func test_십일더하기육빼기() throws {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        // Any test you write for XCTest can be annotated as throws and async.
        // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
        // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
        
        sut.buttonTapped(.one)
        sut.buttonTapped(.one)
        sut.buttonTapped(.add)
        sut.buttonTapped(.six)
        sut.buttonTapped(.equal)
        sut.buttonTapped(.subtract)
        
        XCTAssertEqual(sut.stack.map(\.text).joined(separator: " "), "17 -")
    }
    
    func test_십일더하기육빼기빼기() throws {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        // Any test you write for XCTest can be annotated as throws and async.
        // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
        // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
        
        sut.buttonTapped(.one)
        sut.buttonTapped(.one)
        sut.buttonTapped(.add)
        sut.buttonTapped(.six)
        sut.buttonTapped(.equal)
        sut.buttonTapped(.subtract)
        sut.buttonTapped(.subtract)
        
        XCTAssertEqual(sut.stack.map(\.text).joined(separator: " "), "17 -")
    }
    
    func test_클리어() throws {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        // Any test you write for XCTest can be annotated as throws and async.
        // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
        // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
        
        sut.buttonTapped(.one)
        sut.buttonTapped(.one)
        sut.buttonTapped(.add)
        sut.buttonTapped(.six)
        sut.buttonTapped(.equal)
        sut.buttonTapped(.subtract)
        sut.buttonTapped(.subtract)
        sut.buttonTapped(.clear)
        
        XCTAssertEqual(sut.stack.map(\.text).joined(separator: " "), "")
    }
    
    func test_사십오이레이즈() throws {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        // Any test you write for XCTest can be annotated as throws and async.
        // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
        // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
        
        sut.buttonTapped(.four)
        sut.buttonTapped(.five)
        sut.buttonTapped(.erase)
        
        XCTAssertEqual(sut.stack.map(\.text).joined(separator: " "), "4")
    }

첫번째 테스트는 두자리수 숫자와 더하기 연산 테스트
두번째 테스트는 연산자도 잘 출력되는지 테스트
세번째는 연산자 두번 연속으로 나오는 illegal한 경우에 연산자 두번째거는 잘 무시가 되는지
네번째는 클리어 잘 되는지
마지막은 지우기가 잘 되는지 테스트입니다.

@H0sungKim H0sungKim self-assigned this Dec 26, 2025
Copy link
Collaborator

@Yeonnies Yeonnies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

잘봤습니다!!
스유까지 잘하면 난 어떡하라고... 진짜 문법이 탄탄한건지 뭔지 잘하는 비결좀 알려주세요 제발..
호성시는 항상 제가 리스팩하고 있습니다.. 너무 잘하세요 진짜 제가 배워갑니다.. 맨날 호성시 코드를 보면 걍 어이가 없어요 어떻게 이 방식으로 했지? 이런 의문이 들어서.. 나는 진짜 스택을 써서 계산기 만들줄 몰랐다
근데 저런식으로 네이밍은 좀 오바에여. 테코스에서 네이밍 컨벤션 내가 과제로 줬었는데 좀만 더 신경써주세여~

--편지--
앱잼 같이 하면 재밌을 거 같았는데 아쉽다!
합세 같은 조가 무려 두명이나 가 있어서 플린트는 너무 마음이 쓰인다..
플린트가서도 잘해.. 분명 재밌을 거야 그 조합 맘에 듦..
근데 나 유킷좀 알려줘라

case erase, clear
}

extension CalculatorButtonType {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

감탄스럽다

guard let last = stack.last else { return }
switch last {
case .num(let int):
_ = stack.popLast()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

너 알고리즘 좀 잘하지

// sut = nil
}

func test_십일더하기육() throws {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네이밍 실화니?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants