[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:
2024-03-18 01:53:28 +00:00
committed by javier
parent 7c016b50d6
commit ef6478dcc6
2 changed files with 245 additions and 0 deletions
@@ -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, [])
}
}