♻️ :: Directly access first row of color location matrix instead of having a separate observable

This way we can prevent `colorLocationMatrix` and `colorLocationInitialRow` running out of sync.
This commit is contained in:
Felix Mau
2021-10-02 13:43:52 +02:00
parent 3304f9bb7c
commit 849ef3e945
3 changed files with 4 additions and 49 deletions
@@ -38,18 +38,6 @@ class GradientActivityIndicatorViewModelTestCase: XCTestCase {
XCTAssertEqual(viewModel.gradientLayerColors.value, expectedGradientLayerColors)
}
func testInitializerShouldSetColorLocationInitialRowToCorrectValue() throws {
let receivedColorLocationInitialRow = try XCTUnwrap(viewModel.colorLocationInitialRow.value)
let expectedColorLocationInitialRow = makeColorLocationInitialRow()
// Unfortunately there is no easier way comparing an array of type `NSNumber` / `Double` with a given accuracy.
XCTAssertEqual(receivedColorLocationInitialRow.count, expectedColorLocationInitialRow.count)
for (receivedColorLocation, expectedColorLocation) in zip(receivedColorLocationInitialRow, expectedColorLocationInitialRow) {
XCTAssertEqual(receivedColorLocation.doubleValue, expectedColorLocation.doubleValue, accuracy: .ulpOfOne)
}
}
func testInitializerShouldSetColorLocationMatrixToCorrectValue() throws {
let receivedColorLocationMatrix = try XCTUnwrap(viewModel.colorLocationMatrix.value)
let expectedColorLocationMatrix = makeColorLocationMatrix()
@@ -108,27 +96,6 @@ class GradientActivityIndicatorViewModelTestCase: XCTestCase {
XCTAssertEqual(viewModel.gradientLayerColors.value, expectedGradientLayerColors)
}
func testSettingGradientColorsShouldUpdateColorLocationInitialRowObservable() {
// Given
let gradientColors: [UIColor] = [.red, .yellow, .green]
// When
viewModel.gradientColors = gradientColors
// Then
//
// `gradientColors = [.red, .yellow, .green]`
// `gradientLayerColors = [.red, .yellow, .green, .yellow, .red, .yellow, .green]`
//
// gradientLayerColors | .red | .yellow | .green | .green | .yellow | .red | .yellow | .green
// initialLocations | 0 | 0 | 0 | 0 | 0 | 0 | 0.5 | 1
//
let expectedGradientLocations = [0, 0, 0, 0, 0, 0.5, 1]
let expectedGradientLayerLocations = expectedGradientLocations.map { NSNumber(value: $0) }
XCTAssertEqual(viewModel.colorLocationInitialRow.value, expectedGradientLayerLocations)
}
func testSettingGradientColorsShouldUpdateColorLocationMatrixObservable() {
// Given
let gradientColors: [UIColor] = [.red, .yellow, .green]
@@ -255,7 +222,6 @@ extension GradientActivityIndicatorViewModelTestCase {
// ...
// 0 | 0.2 | 0.4 | 0.6 | 0.8 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1
//
let colorLocationMatrix = [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.2, 0.4, 0.6, 0.8, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.2, 0.4, 0.6, 0.8, 1, 1],