-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec5c936
commit c06b403
Showing
2 changed files
with
91 additions
and
118 deletions.
There are no files selected for viewing
118 changes: 0 additions & 118 deletions
118
Tests/InstantSearchCoreTests/Unit/DynamicFacets/BuildOrderTests.swift
This file was deleted.
Oops, something went wrong.
91 changes: 91 additions & 0 deletions
91
Tests/InstantSearchCoreTests/Unit/DynamicFacets/FacetsOrdererTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// | ||
// FacetsOrdererTests.swift | ||
// | ||
// | ||
// Created by Vladislav Fitc on 14/04/2021. | ||
// | ||
|
||
import Foundation | ||
@testable import InstantSearchCore | ||
import XCTest | ||
|
||
class FacetsOrdererTests: XCTestCase { | ||
|
||
let facets: [Attribute: [Facet]] = [ | ||
"size": [ | ||
Facet(value: "XS", count: 82), | ||
Facet(value: "L", count: 81), | ||
Facet(value: "XXXL", count: 73), | ||
Facet(value: "XXL", count: 71), | ||
Facet(value: "M", count: 67), | ||
Facet(value: "S", count: 67), | ||
Facet(value: "XL", count: 67), | ||
], | ||
"brand": [ | ||
Facet(value: "Dyson", count: 53), | ||
Facet(value: "Sony", count: 53), | ||
Facet(value: "Apple", count: 51), | ||
Facet(value: "Uniqlo", count: 43), | ||
], | ||
"color": [ | ||
Facet(value: "yellow", count: 65), | ||
Facet(value: "blue", count: 63), | ||
Facet(value: "red", count: 58), | ||
Facet(value: "violet", count: 55), | ||
Facet(value: "orange", count: 54), | ||
Facet(value: "green", count: 48), | ||
], | ||
"country": [ | ||
Facet(value: "Spain", count: 31), | ||
Facet(value: "Finland", count: 27), | ||
Facet(value: "Germany", count: 27), | ||
Facet(value: "UK", count: 26), | ||
Facet(value: "Italy", count: 25), | ||
Facet(value: "France", count: 23), | ||
Facet(value: "Denmark", count: 22), | ||
Facet(value: "USA", count: 19), | ||
] | ||
] | ||
|
||
func withOrder(_ facetOrder: FacetOrdering) -> [AttributedFacets] { | ||
return FacetsOrderer(facetOrder: facetOrder, facets: facets)() | ||
} | ||
|
||
func testStrictFacetsOrder() { | ||
let facets: [Attribute] = ["size", "brand", "color", "country"].shuffled() | ||
let order = FacetOrdering(facets: .init(order: facets), values: [:]) | ||
XCTAssertEqual(withOrder(order).map(\.attribute), facets) | ||
} | ||
|
||
func testPartialFacetsOrder() { | ||
let facets: [Attribute] = ["size", "country"] | ||
let order = FacetOrdering(facets: .init(order: facets), values: [:]) | ||
XCTAssertEqual(withOrder(order).map(\.attribute), facets) | ||
} | ||
|
||
func testStrictFacetValuesOrder() { | ||
let countries = ["UK", "France", "USA", "Germany", "Finland", "Denmark", "Italy", "Spain"].shuffled() | ||
let order = FacetOrdering(facets: .init(order: ["country"]), values: ["country": .init(order: countries, sortRemainingBy: .none)]) | ||
XCTAssertEqual(withOrder(order).first(where: { $0.attribute == "country" })?.facets.map(\.value), countries) | ||
} | ||
|
||
func testPartialFacetValuesOrder() { | ||
let countries = ["UK", "France", "USA"].shuffled() | ||
let order = FacetOrdering(facets: .init(order: ["country"]), values: ["country": .init(order: countries, sortRemainingBy: .none)]) | ||
XCTAssertEqual(withOrder(order).first(where: { $0.attribute == "country" })?.facets.map(\.value), countries) | ||
} | ||
|
||
func testPartiallyStrictFacetValuesOrder() { | ||
let countries = ["UK", "France", "USA"] | ||
let order = FacetOrdering(facets: .init(order: ["country"]), values: ["country": .init(order: countries, sortRemainingBy: .alpha)]) | ||
XCTAssertEqual(withOrder(order).first(where: { $0.attribute == "country" })?.facets.map(\.value), countries + ["Germany", "Finland", "Denmark", "Italy", "Spain"].sorted()) | ||
} | ||
|
||
func testSortFacetValuesByCount() { | ||
let expectedFacetValues = facets["country"]?.sorted(by: { $0.count > $1.count }).map(\.value) | ||
let order = FacetOrdering(facets: .init(order: ["country"]), values: ["country": .init(order: [], sortRemainingBy: .count)]) | ||
XCTAssertEqual(withOrder(order).first(where: { $0.attribute == "country" })?.facets.map(\.value), expectedFacetValues) | ||
} | ||
|
||
|
||
} |