mirror of
https://github.com/kucherenko/jscpd.git
synced 2026-09-19 08:11:03 +08:00
64e471e2b0
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
58 lines
1.6 KiB
Plaintext
58 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 students at risk (average < 70)
|
|
atRiskStudents :: Array Student -> Array Student
|
|
atRiskStudents students =
|
|
filter (\s -> average s.grades < 70.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: [62.0, 58.0, 65.0], major: "Math" }
|
|
, { id: 3, name: "Carol", grades: [91.0, 95.0, 89.0], major: "CS" }
|
|
]
|
|
let atRisk = atRiskStudents students
|
|
logShow $ map _.name atRisk
|