[Library] Word filtering in Foundation library (#6)
This PR contains the work done to Implemented the `FilterWordsUseCase` use case in the Foundation library, which will be used to filter the content of the reviews. Reviewed-on: rock-n-code/app-reviews#6 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #6.
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
//
|
||||
// FilterWordsUseCaseTests.swift
|
||||
// ReviewsFoundationTest
|
||||
//
|
||||
// Created by Javier Cicchelli on 18/03/2024.
|
||||
// Copyright © 2024 Röck+Cöde VoF. All rights reserved.
|
||||
//
|
||||
|
||||
import ReviewsFoundationKit
|
||||
import XCTest
|
||||
|
||||
final class FilterWordsUseCaseTests: XCTestCase {
|
||||
|
||||
// MARK: Properties
|
||||
private var input: FilterWordsUseCase.Input!
|
||||
private var output: FilterWordsUseCase.Output!
|
||||
private var sut: FilterWordsUseCase!
|
||||
|
||||
// MARK: Setup
|
||||
override func setUp() async throws {
|
||||
sut = .init()
|
||||
}
|
||||
|
||||
// MARK: Function tests
|
||||
func testCallAsFunction_withInput_hasSomeLongWords() throws {
|
||||
// GIVEN
|
||||
input = "one two three four five six seven eight nine ten"
|
||||
|
||||
// WHEN
|
||||
output = try sut(input)
|
||||
|
||||
// THEN
|
||||
XCTAssertFalse(output.isEmpty)
|
||||
XCTAssertEqual(output, [
|
||||
.init(word: "Eight", count: 1),
|
||||
.init(word: "Five", count: 1),
|
||||
.init(word: "Four", count: 1),
|
||||
.init(word: "Nine", count: 1),
|
||||
.init(word: "Seven", count: 1),
|
||||
.init(word: "Three", count: 1),
|
||||
])
|
||||
}
|
||||
|
||||
func testCallAsFunction_withInput_hasSomeRepeatedLongWords() throws {
|
||||
// GIVEN
|
||||
input = "one two three three four five five six seven eight nine nine ten"
|
||||
|
||||
// WHEN
|
||||
output = try sut(input)
|
||||
|
||||
// THEN
|
||||
XCTAssertFalse(output.isEmpty)
|
||||
XCTAssertEqual(output, [
|
||||
.init(word: "Five", count: 2),
|
||||
.init(word: "Nine", count: 2),
|
||||
.init(word: "Three", count: 2),
|
||||
.init(word: "Eight", count: 1),
|
||||
.init(word: "Four", count: 1),
|
||||
.init(word: "Seven", count: 1),
|
||||
])
|
||||
}
|
||||
|
||||
func testCallAsFunction_withInput_hasSomeRepeatedCaseSensitiveLongWords() throws {
|
||||
// GIVEN
|
||||
input = "one two three Three four Five five six seven eight nine nine ten"
|
||||
|
||||
// WHEN
|
||||
output = try sut(input)
|
||||
|
||||
// THEN
|
||||
XCTAssertFalse(output.isEmpty)
|
||||
XCTAssertEqual(output, [
|
||||
.init(word: "Five", count: 2),
|
||||
.init(word: "Nine", count: 2),
|
||||
.init(word: "Three", count: 2),
|
||||
.init(word: "Eight", count: 1),
|
||||
.init(word: "Four", count: 1),
|
||||
.init(word: "Seven", count: 1),
|
||||
])
|
||||
}
|
||||
|
||||
func testCallAsFunction_withInput_hasSomeRepeatedDiacriticSensitiveLongWords() throws {
|
||||
// GIVEN
|
||||
input = "one two thrèé Three four Fíve fïve six Šëvêń seven eight niñe nine ten"
|
||||
|
||||
// WHEN
|
||||
output = try sut(input)
|
||||
|
||||
// THEN
|
||||
XCTAssertFalse(output.isEmpty)
|
||||
XCTAssertEqual(output, [
|
||||
.init(word: "Five", count: 2),
|
||||
.init(word: "Nine", count: 2),
|
||||
.init(word: "Seven", count: 2),
|
||||
.init(word: "Three", count: 2),
|
||||
.init(word: "Eight", count: 1),
|
||||
.init(word: "Four", count: 1),
|
||||
])
|
||||
}
|
||||
|
||||
func testCallAsFunction_withInput_hasOnlyShortWords() throws {
|
||||
// GIVEN
|
||||
input = "no one is a two"
|
||||
|
||||
// WHEN
|
||||
output = try sut(input)
|
||||
|
||||
// THEN
|
||||
XCTAssertTrue(output.isEmpty)
|
||||
XCTAssertEqual(output, [])
|
||||
}
|
||||
|
||||
func testCallAsFunction_withEmptyInput() throws {
|
||||
// GIVEN
|
||||
input = .empty
|
||||
|
||||
// WHEN
|
||||
output = try sut(input)
|
||||
|
||||
// THEN
|
||||
XCTAssertTrue(output.isEmpty)
|
||||
XCTAssertEqual(output, [])
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user