feat: Uses new testing package for some tests
This commit is contained in:
@@ -9,14 +9,14 @@ public struct EquipmentMeasurementForm {
|
|||||||
|
|
||||||
public init() { }
|
public init() { }
|
||||||
|
|
||||||
@Reducer(state: .equatable)
|
@Reducer(state: .equatable, .sendable, action: .sendable)
|
||||||
public enum Destination {
|
public enum Destination {
|
||||||
case flaggedMeasurementsList(FlaggedMeasurementsList)
|
case flaggedMeasurementsList(FlaggedMeasurementsList)
|
||||||
case infoView(InfoViewFeature)
|
case infoView(InfoViewFeature)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ObservableState
|
@ObservableState
|
||||||
public struct State: Equatable {
|
public struct State: Equatable, Sendable {
|
||||||
@Presents public var destination: Destination.State?
|
@Presents public var destination: Destination.State?
|
||||||
@Shared public var sharedSettings: SharedPressureEstimationSettings
|
@Shared public var sharedSettings: SharedPressureEstimationSettings
|
||||||
public var allowEquipmentTypeSelection: Bool
|
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 airflow: Double?
|
||||||
public var returnPlenumPressure: Double?
|
public var returnPlenumPressure: Double?
|
||||||
public var postFilterPressure: 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 returnPlenumPressure
|
||||||
case postFilterPressure
|
case postFilterPressure
|
||||||
case coilPressure
|
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 binding(BindingAction<State>)
|
||||||
case destination(PresentationAction<Destination.Action>)
|
case destination(PresentationAction<Destination.Action>)
|
||||||
case view(View)
|
case view(View)
|
||||||
|
|
||||||
@CasePathable
|
@CasePathable
|
||||||
public enum View {
|
public enum View: Sendable {
|
||||||
case infoButtonTapped
|
case infoButtonTapped
|
||||||
case nextButtonTapped
|
case nextButtonTapped
|
||||||
case onAppear
|
case onAppear
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import Dependencies
|
|||||||
import EstimatedPressureDependency
|
import EstimatedPressureDependency
|
||||||
import SharedModels
|
import SharedModels
|
||||||
import XCTest
|
import XCTest
|
||||||
|
import Testing
|
||||||
|
|
||||||
final class PositiveNumericTests: XCTestCase {
|
final class PositiveNumericTests: XCTestCase {
|
||||||
|
|
||||||
@@ -40,6 +41,8 @@ final class PositiveNumericTests: XCTestCase {
|
|||||||
func testExternalStaticPressure() {
|
func testExternalStaticPressure() {
|
||||||
var envelope = EquipmentMeasurement.furnaceAndCoil(
|
var envelope = EquipmentMeasurement.furnaceAndCoil(
|
||||||
.init(
|
.init(
|
||||||
|
airflow: 1200,
|
||||||
|
manufacturersIncludedFilterPressureDrop: 0,
|
||||||
returnPlenumPressure: -0.1,
|
returnPlenumPressure: -0.1,
|
||||||
postFilterPressure: -0.2, // here to test it makes positive.
|
postFilterPressure: -0.2, // here to test it makes positive.
|
||||||
preCoilPressure: 0.4,
|
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)
|
XCTAssertEqual(round(sut * 10) / 10, 0.6)
|
||||||
|
|
||||||
|
|
||||||
envelope = .airHandler(
|
envelope = .airHandler(
|
||||||
.init(
|
.init(
|
||||||
|
airflow: 1200,
|
||||||
|
manufacturersIncludedFilterPressureDrop: 0,
|
||||||
returnPlenumPressure: -0.2,
|
returnPlenumPressure: -0.2,
|
||||||
postFilterPressure: 0.3,
|
postFilterPressure: 0.3,
|
||||||
postCoilPressure: 0.5,
|
postCoilPressure: 0.5,
|
||||||
supplyPlenumPressure: 0.3)
|
supplyPlenumPressure: 0.3)
|
||||||
)
|
)
|
||||||
|
|
||||||
sut = envelope.externalStaticPressure
|
sut = envelope.externalStaticPressure.positiveValue
|
||||||
XCTAssertEqual(round(sut * 10) / 10, 0.7)
|
XCTAssertEqual(round(sut * 10) / 10, 0.7)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testExternalStaticPressureReturnsZero() {
|
@Test(
|
||||||
XCTAssertEqual(
|
"Values are positive only",
|
||||||
EquipmentMeasurement.airHandler(.init()).externalStaticPressure,
|
arguments: [
|
||||||
0
|
0.1,
|
||||||
|
-0.1
|
||||||
|
]
|
||||||
)
|
)
|
||||||
XCTAssertEqual(
|
func valuesArePositiveOnly(value: Double) {
|
||||||
EquipmentMeasurement.furnaceAndCoil(.init()).externalStaticPressure,
|
let positive = Positive<Double>(value)
|
||||||
0
|
#expect(positive.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 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
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 SharedModels
|
||||||
|
import Testing
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
final class PercentageTests: XCTestCase {
|
struct PercentagePostfixOperatorTests {
|
||||||
|
static let arguments: [(Percentage, Double)] = [
|
||||||
|
(50%, 50),
|
||||||
|
(50.01%, 50.01),
|
||||||
|
(110%, 110)
|
||||||
|
]
|
||||||
|
|
||||||
func testPostfixOperator() {
|
@Test("Percentage Postfix Operator", arguments: Self.arguments)
|
||||||
var sut = 50%
|
func postfixTest(percentage: Percentage, expectation: Double) {
|
||||||
XCTAssertEqual(sut.rawValue, 50)
|
#expect(percentage.rawValue == expectation)
|
||||||
|
|
||||||
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%")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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