|
| 1 | +import Testing |
| 2 | +import Helical |
| 3 | +import Cadova |
| 4 | + |
| 5 | +private func isClose(_ a: Double, _ b: Double, tolerance: Double = 1e-9) -> Bool { abs(a - b) < tolerance } |
| 6 | + |
| 7 | +struct CountersunkHeadTests { |
| 8 | + @Test func `height is (topDiameter - boltDiameter) / 2 × tan(angle / 2)`() { |
| 9 | + let noLens = CountersunkBoltHeadShape(angle: 90°, topDiameter: 10, boltDiameter: 5) |
| 10 | + #expect(isClose(noLens.height, 2.5, tolerance: 1e-6)) |
| 11 | + |
| 12 | + // 82° uses angle/2 = 41°, not the full angle |
| 13 | + let angled = CountersunkBoltHeadShape(angle: 82°, topDiameter: 8, boltDiameter: 4) |
| 14 | + #expect(isClose(angled.height, 2.0 * tan(41°), tolerance: 1e-6)) |
| 15 | + } |
| 16 | + |
| 17 | + @Test func `lens height adds to total height but not consumed length`() { |
| 18 | + let shape = CountersunkBoltHeadShape(angle: 90°, topDiameter: 10, boltDiameter: 5, lensHeight: 1) |
| 19 | + #expect(isClose(shape.height, 3.5, tolerance: 1e-6)) |
| 20 | + #expect(isClose(shape.consumedLength, 2.5, tolerance: 1e-6)) |
| 21 | + } |
| 22 | + |
| 23 | + @Test func `consumed length equals height minus lens height`() { |
| 24 | + let shape = CountersunkBoltHeadShape(angle: 90°, topDiameter: 12, boltDiameter: 6, lensHeight: 1.5) |
| 25 | + #expect(isClose(shape.consumedLength, shape.height - 1.5)) |
| 26 | + } |
| 27 | +} |
0 commit comments