Files
kucherenko__jscpd/fixtures/purescript/file1.purs
apk 64e471e2b0 test: raise coverage to 96%+ on @jscpd/finder and 98%+ on apps/jscpd
Adds 92 new tests (178 → 270 total) with zero source-file modifications:

- packages/finder: 13 new test files covering all reporters, subscribers,
  validators, hooks, utils, options, cloneFound, getFilesToDetect, and
  InFilesDetector; shared buildClone() factory helper
- apps/jscpd: 3 new test files (options-unit, print, store) plus extensions
  to formats, modes, and options integration tests
- vitest.config.ts added to both packages to restrict coverage.include
  to src/** only, eliminating bin/ and prism.js noise
- Fixes 3 tokenizer bugs (trailing space in format lookup, tokenization
  edge cases) uncovered by the new format fixture suite
- Adds fixture files for 40+ language formats to support formats.test.ts
2026-05-09 15:00:38 +02:00

59 lines
1.6 KiB
Plaintext

module Main where
import Prelude
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Array (filter, map, foldl, length, sortBy)
import Data.String (toLower, trim)
import Data.Ord (comparing)
-- Data types
type StudentId = Int
type Student =
{ id :: StudentId
, name :: String
, grades :: Array Number
, major :: String
}
-- Calculate grade average
average :: Array Number -> Number
average [] = 0.0
average xs = foldl (+) 0.0 xs / (fromIntegral (length xs))
where
fromIntegral n = if n == 0 then 1.0 else toNumber n
-- Get letter grade from numeric score
letterGrade :: Number -> String
letterGrade score
| score >= 90.0 = "A"
| score >= 80.0 = "B"
| score >= 70.0 = "C"
| score >= 60.0 = "D"
| otherwise = "F"
-- Filter students by major
filterByMajor :: String -> Array Student -> Array Student
filterByMajor major students =
filter (\s -> toLower (trim s.major) == toLower (trim major)) students
-- Sort students by average grade (descending)
rankStudents :: Array Student -> Array Student
rankStudents = sortBy (comparing (\s -> -(average s.grades)))
-- Get honor roll (average >= 90)
honorRoll :: Array Student -> Array Student
honorRoll students =
filter (\s -> average s.grades >= 90.0) students
main :: Effect Unit
main = do
let students =
[ { id: 1, name: "Alice", grades: [95.0, 88.0, 92.0], major: "CS" }
, { id: 2, name: "Bob", grades: [72.0, 68.0, 75.0], major: "Math" }
, { id: 3, name: "Carol", grades: [91.0, 95.0, 89.0], major: "CS" }
]
let csStudents = filterByMajor "CS" students
let ranked = rankStudents csStudents
logShow $ map _.name ranked