feat: Uses new testing package for some tests
This commit is contained in:
@@ -9,14 +9,14 @@ public struct EquipmentMeasurementForm {
|
||||
|
||||
public init() { }
|
||||
|
||||
@Reducer(state: .equatable)
|
||||
@Reducer(state: .equatable, .sendable, action: .sendable)
|
||||
public enum Destination {
|
||||
case flaggedMeasurementsList(FlaggedMeasurementsList)
|
||||
case infoView(InfoViewFeature)
|
||||
}
|
||||
|
||||
@ObservableState
|
||||
public struct State: Equatable {
|
||||
public struct State: Equatable, Sendable {
|
||||
@Presents public var destination: Destination.State?
|
||||
@Shared public var sharedSettings: SharedPressureEstimationSettings
|
||||
public var allowEquipmentTypeSelection: Bool
|
||||
@@ -65,7 +65,7 @@ public struct EquipmentMeasurementForm {
|
||||
}
|
||||
}
|
||||
|
||||
public struct Measurements: Equatable {
|
||||
public struct Measurements: Equatable, Sendable {
|
||||
public var airflow: Double?
|
||||
public var returnPlenumPressure: Double?
|
||||
public var postFilterPressure: Double?
|
||||
@@ -136,7 +136,7 @@ public struct EquipmentMeasurementForm {
|
||||
}
|
||||
}
|
||||
|
||||
public enum Field: CaseIterable, FocusableField, Hashable, Identifiable {
|
||||
public enum Field: CaseIterable, FocusableField, Hashable, Identifiable, Sendable {
|
||||
case returnPlenumPressure
|
||||
case postFilterPressure
|
||||
case coilPressure
|
||||
@@ -148,13 +148,13 @@ public struct EquipmentMeasurementForm {
|
||||
}
|
||||
}
|
||||
|
||||
public enum Action: BindableAction, ViewAction {
|
||||
public enum Action: BindableAction, ViewAction, Sendable {
|
||||
case binding(BindingAction<State>)
|
||||
case destination(PresentationAction<Destination.Action>)
|
||||
case view(View)
|
||||
|
||||
@CasePathable
|
||||
public enum View {
|
||||
public enum View: Sendable {
|
||||
case infoButtonTapped
|
||||
case nextButtonTapped
|
||||
case onAppear
|
||||
|
||||
@@ -2,6 +2,7 @@ import Dependencies
|
||||
import EstimatedPressureDependency
|
||||
import SharedModels
|
||||
import XCTest
|
||||
import Testing
|
||||
|
||||
final class PositiveNumericTests: XCTestCase {
|
||||
|
||||
@@ -40,6 +41,8 @@ final class PositiveNumericTests: XCTestCase {
|
||||
func testExternalStaticPressure() {
|
||||
var envelope = EquipmentMeasurement.furnaceAndCoil(
|
||||
.init(
|
||||
airflow: 1200,
|
||||
manufacturersIncludedFilterPressureDrop: 0,
|
||||
returnPlenumPressure: -0.1,
|
||||
postFilterPressure: -0.2, // here to test it makes positive.
|
||||
preCoilPressure: 0.4,
|
||||
@@ -47,48 +50,47 @@ final class PositiveNumericTests: XCTestCase {
|
||||
)
|
||||
)
|
||||
|
||||
var sut = envelope.externalStaticPressure
|
||||
var sut = envelope.externalStaticPressure.positiveValue
|
||||
XCTAssertEqual(round(sut * 10) / 10, 0.6)
|
||||
|
||||
|
||||
envelope = .airHandler(
|
||||
.init(
|
||||
airflow: 1200,
|
||||
manufacturersIncludedFilterPressureDrop: 0,
|
||||
returnPlenumPressure: -0.2,
|
||||
postFilterPressure: 0.3,
|
||||
postCoilPressure: 0.5,
|
||||
supplyPlenumPressure: 0.3)
|
||||
)
|
||||
|
||||
sut = envelope.externalStaticPressure
|
||||
sut = envelope.externalStaticPressure.positiveValue
|
||||
XCTAssertEqual(round(sut * 10) / 10, 0.7)
|
||||
|
||||
}
|
||||
|
||||
func testExternalStaticPressureReturnsZero() {
|
||||
XCTAssertEqual(
|
||||
EquipmentMeasurement.airHandler(.init()).externalStaticPressure,
|
||||
0
|
||||
)
|
||||
XCTAssertEqual(
|
||||
EquipmentMeasurement.furnaceAndCoil(.init()).externalStaticPressure,
|
||||
0
|
||||
)
|
||||
@Test(
|
||||
"Values are positive only",
|
||||
arguments: [
|
||||
0.1,
|
||||
-0.1
|
||||
]
|
||||
)
|
||||
func valuesArePositiveOnly(value: Double) {
|
||||
let positive = Positive<Double>(value)
|
||||
#expect(positive.positiveValue == 0.1)
|
||||
}
|
||||
|
||||
func testValuesArePositiveOnly() {
|
||||
let sut = Positive<Double>(wrappedValue: -0.1)
|
||||
XCTAssertEqual(sut.positiveValue, 0.1)
|
||||
|
||||
let sut2 = Positive<Double?>(wrappedValue: -0.1)
|
||||
XCTAssertEqual(sut2.positiveValue, 0.1)
|
||||
@Test(
|
||||
"PlenumDimension area calculation",
|
||||
arguments: [
|
||||
(PlenumDimension.rectangular(width: 24, height: 12), 2),
|
||||
(PlenumDimension.round(16), 1.4)
|
||||
]
|
||||
)
|
||||
func plenumDimensionArea(dimension: PlenumDimension, expectation: Double) {
|
||||
let sut = round(dimension.areaInSquareFeet * 100) / 100
|
||||
#expect(sut == expectation)
|
||||
}
|
||||
|
||||
func testReturnPlenumDimensionsAreaCalculation() {
|
||||
var sut = PlenumDimension.rectangular(width: 24, height: 12)
|
||||
XCTAssertEqual(sut.areaInSquareFeet, 2)
|
||||
|
||||
sut = .round(16)
|
||||
XCTAssertEqual(round(sut.areaInSquareFeet * 100) / 100, 1.4)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +1,72 @@
|
||||
import SharedModels
|
||||
import Testing
|
||||
import XCTest
|
||||
|
||||
final class PercentageTests: XCTestCase {
|
||||
struct PercentagePostfixOperatorTests {
|
||||
static let arguments: [(Percentage, Double)] = [
|
||||
(50%, 50),
|
||||
(50.01%, 50.01),
|
||||
(110%, 110)
|
||||
]
|
||||
|
||||
func testPostfixOperator() {
|
||||
var sut = 50%
|
||||
XCTAssertEqual(sut.rawValue, 50)
|
||||
|
||||
sut = 50.01%
|
||||
XCTAssertEqual(sut.rawValue, 50.01)
|
||||
}
|
||||
|
||||
func testFractionInitialization() {
|
||||
let sut = Percentage(fraction: 0.5)
|
||||
XCTAssertEqual(sut.rawValue, 50)
|
||||
XCTAssertEqual(sut.fraction, 0.5)
|
||||
}
|
||||
|
||||
func testExpressibleByFloatLiteral() {
|
||||
let sut: Percentage = 50.01
|
||||
XCTAssertEqual(sut.rawValue, 50.01)
|
||||
}
|
||||
|
||||
func testExpressibleByIntegerLiteral() {
|
||||
let sut: Percentage = 50
|
||||
XCTAssertEqual(sut.rawValue, 50)
|
||||
}
|
||||
|
||||
func testMultiplication() {
|
||||
var sut = 2% * 25%
|
||||
XCTAssertEqual(sut, 50%)
|
||||
|
||||
sut *= 2
|
||||
XCTAssertEqual(sut, 100%)
|
||||
}
|
||||
|
||||
func testAddition() {
|
||||
var sut = 35% + 15%
|
||||
XCTAssertEqual(sut, 50%)
|
||||
|
||||
sut += 25%
|
||||
XCTAssertEqual(sut, 75%)
|
||||
}
|
||||
|
||||
func testSubtraction() {
|
||||
let sut = 50% - 15%
|
||||
XCTAssertEqual(sut, 35%)
|
||||
}
|
||||
|
||||
func testComparable() {
|
||||
let sut1 = 50%
|
||||
let sut2 = 35%
|
||||
|
||||
XCTAssert(sut2 < sut1)
|
||||
}
|
||||
|
||||
func testCustomStringConvertible() {
|
||||
let sut = 50%
|
||||
XCTAssertEqual(sut.description, "50%")
|
||||
@Test("Percentage Postfix Operator", arguments: Self.arguments)
|
||||
func postfixTest(percentage: Percentage, expectation: Double) {
|
||||
#expect(percentage.rawValue == expectation)
|
||||
}
|
||||
}
|
||||
|
||||
struct PercentageInitializationTests {
|
||||
|
||||
@Test("Percentage expressible tests")
|
||||
func percentageExpressible(){
|
||||
let intLiteral: Percentage = 50
|
||||
#expect(intLiteral.rawValue == 50)
|
||||
|
||||
let floatLiteral: Percentage = 50.01
|
||||
#expect(floatLiteral.rawValue == 50.01)
|
||||
}
|
||||
|
||||
@Test("Fraction initialization")
|
||||
func fraction() {
|
||||
let sut = Percentage(fraction: 0.5)
|
||||
#expect(sut.rawValue == 50)
|
||||
#expect(sut.fraction == 0.5)
|
||||
}
|
||||
}
|
||||
|
||||
struct PercentageMathTests {
|
||||
|
||||
let first = 2%
|
||||
let second = 25%
|
||||
|
||||
@Test("Percentage addition")
|
||||
func addition() {
|
||||
let sut = first + second
|
||||
#expect(sut == 27%)
|
||||
}
|
||||
|
||||
@Test("Percentage subtraction")
|
||||
func subtraction() {
|
||||
let sut = second - first
|
||||
#expect(sut == 23%)
|
||||
}
|
||||
|
||||
@Test("Percentage multiplication")
|
||||
func multiplication() {
|
||||
let sut = first * second
|
||||
#expect(sut == 50%)
|
||||
}
|
||||
|
||||
@Test("Percentage comparable")
|
||||
func comparable() {
|
||||
#expect(first < second)
|
||||
#expect(second > first)
|
||||
#expect(first >= first)
|
||||
#expect(second <= second)
|
||||
}
|
||||
}
|
||||
|
||||
@Test("Percentage custom string convertible")
|
||||
func percentageString() {
|
||||
#expect(50%.description == "50%")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user