diff --git a/Sources/CrapCore/Severity.swift b/Sources/CrapCore/Severity.swift new file mode 100644 index 0000000..008fb8c --- /dev/null +++ b/Sources/CrapCore/Severity.swift @@ -0,0 +1,12 @@ +import Foundation + +/// Human-readable severity band for a CRAP score, relative to a threshold. +/// (Deliberately shipped without tests to demonstrate crap4swift flagging it.) +public func severity(forCrap crap: Double, threshold: Double) -> String { + if crap <= threshold * 0.25 { return "trivial" } + if crap <= threshold * 0.5 { return "low" } + if crap <= threshold { return "watch" } + if crap <= threshold * 3 { return "high" } + if crap <= threshold * 10 { return "severe" } + return "critical" +} diff --git a/Tests/CrapCoreTests/SeverityTests.swift b/Tests/CrapCoreTests/SeverityTests.swift new file mode 100644 index 0000000..17ee3ce --- /dev/null +++ b/Tests/CrapCoreTests/SeverityTests.swift @@ -0,0 +1,17 @@ +import Testing +@testable import CrapCore + +@Suite("CRAP severity bands") +struct SeverityTests { + @Test("classifies each band relative to the threshold", arguments: [ + (10.0, "trivial"), // <= 25 + (40.0, "low"), // <= 50 + (80.0, "watch"), // <= 100 + (200.0, "high"), // <= 300 + (800.0, "severe"), // <= 1000 + (2000.0, "critical"), + ]) + func bands(crap: Double, expected: String) { + #expect(severity(forCrap: crap, threshold: 100) == expected) + } +} diff --git a/default.profraw b/default.profraw new file mode 100644 index 0000000..b9ed84d Binary files /dev/null and b/default.profraw differ