[Library] Filter library (#7)

This PR contains the work done to create the `Filter` library into the **Libraries** package, and moved the `FilterWordsUseCase` use case to it from the `Foundation` library.

Reviewed-on: rock-n-code/app-reviews#7
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 #7.
This commit is contained in:
2024-03-18 02:22:25 +00:00
committed by javier
parent ef6478dcc6
commit 72a8e77fc7
6 changed files with 20 additions and 42 deletions
@@ -1,125 +0,0 @@
//
// 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, [])
}
}