File: git_diff_typescript.txt

package info (click to toggle)
diff-cover 10.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,256 kB
  • sloc: python: 6,452; xml: 218; cpp: 18; sh: 12; makefile: 10
file content (45 lines) | stat: -rw-r--r-- 963 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
diff --git a/src/calculator.ts b/src/calculator.ts
new file mode 100644
index 0000000..fedcba0
--- /dev/null
+++ b/src/calculator.ts
@@ -0,0 +1,40 @@
+export class Calculator {
+  // Function coverage
+  add(a: number, b: number): number {
+    return a + b;
+  }
+
+  // Branch coverage
+  divide(a: number, b: number): number {
+    if (b === 0) {
+      throw new Error("Division by zero");
+    }
+    return a / b;
+  }
+
+  // Anonymous function coverage
+  processNumbers(
+    numbers: number[],
+    processor: (n: number) => number = (n) => n * 2
+  ): number[] {
+    return numbers.map(processor);
+  }
+
+  // Line and branch coverage
+  getGrade(score: number): string {
+    if (score < 0 || score > 100) {
+      throw new Error("Invalid score");
+    }
+
+    if (score >= 90) {
+      return "A";
+    } else if (score >= 80) {
+      return "B";
+    } else if (score >= 70) {
+      return "C";
+    } else {
+      return "F";
+    }
+  }
+}