Skip to content

Commit

Permalink
Indicate infinite capacitance for zero reactance (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfikes authored Jan 28, 2024
1 parent c7160a0 commit 3ac0af7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Impedance Converter/Impedance Converter/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class ViewModel: ObservableObject, Codable {
get {
switch circuitMode {
case .series:
return -1 / (omega * reactance)
return reactance.isZero ? Double.infinity : -1 / (omega * reactance)
case .parallel:
return susceptance / omega
}
Expand All @@ -435,7 +435,7 @@ class ViewModel: ObservableObject, Codable {
case .series:
return reactance / omega
case .parallel:
return -1 / (susceptance * omega)
return susceptance.isZero ? Double.infinity : -1 / (susceptance * omega)
}
}
set {
Expand Down
12 changes: 12 additions & 0 deletions Impedance Converter/Impedance ConverterTests/ViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@ class ReactiveParametersTests: ViewModelTestBase {
viewModel.inductance = newInductance
XCTAssertEqual(viewModel.reactance, newInductance * viewModel.omega)
}

func testInductanceWithZeroSusceptance() {
viewModel.susceptance = 0
viewModel.circuitMode = .parallel
XCTAssertEqual(viewModel.inductance, Double.infinity)
}

// Testing Capacitance
func testCapacitance() {
Expand All @@ -358,6 +364,12 @@ class ReactiveParametersTests: ViewModelTestBase {
viewModel.capacitance = newCapacitance
XCTAssertEqual(viewModel.susceptance, newCapacitance * viewModel.omega)
}

func testCapacitanceWithZeroReactance() {
viewModel.reactance = 0
viewModel.circuitMode = .series
XCTAssertEqual(viewModel.capacitance, Double.infinity)
}

// Testing Dissipation Factor (D)
func testDissipationFactor() {
Expand Down

0 comments on commit 3ac0af7

Please sign in to comment.