Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Sources/CrapCore/Severity.swift
Original file line number Diff line number Diff line change
@@ -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"
}
17 changes: 17 additions & 0 deletions Tests/CrapCoreTests/SeverityTests.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
Binary file added default.profraw
Binary file not shown.
Loading