• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

source-academy / js-slang / 11929582114

20 Nov 2024 08:33AM UTC coverage: 81.654% (+0.04%) from 81.61%
11929582114

Pull #1728

github

web-flow
Merge c3f0269a5 into 665233634
Pull Request #1728: Implement the CSET machine, along with macros

3654 of 4864 branches covered (75.12%)

Branch coverage included in aggregate %.

491 of 596 new or added lines in 11 files covered. (82.38%)

1 existing line in 1 file now uncovered.

11474 of 13663 relevant lines covered (83.98%)

143610.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.0
/src/cse-machine/macro-utils.ts
1
import { List, Pair } from '../stdlib/list'
2

3
/**
4
 * Low-level check for a list.
5
 * @param value any value
6
 * @returns whether the value is a list
7
 */
8
export function isList(value: any): value is List {
80✔
9
  if (value === null) {
100,941✔
10
    return true
18,296✔
11
  }
12
  return Array.isArray(value) && value.length === 2 && isList(value[1])
82,645✔
13
}
14

15
/**
16
 * Turn a list into an array.
17
 * @param value a list
18
 * @returns
19
 */
20
export function flattenList(value: List): any[] {
80✔
21
  if (value === null) {
67,880✔
22
    return []
17,789✔
23
  }
24
  return [value[0], ...flattenList(value[1])]
50,091✔
25
}
26

27
/**
28
 * Convert an array into a list.
29
 * @param arr
30
 * @returns
31
 */
32
export function arrayToList(arr: any[]): List {
80✔
33
  return arrayToImproperList(arr, null) as List
3,349✔
34
}
35

36
/**
37
 * Convert an array into an improper list.
38
 * @param arr
39
 * @param last
40
 * @returns
41
 */
42
export function arrayToImproperList(arr: any[], last: any): any {
80✔
43
  if (arr.length === 0) {
13,228✔
44
    return last
3,584✔
45
  }
46
  const pair: any[] = [arr[0], arrayToImproperList(arr.slice(1), last)] as any[]
9,644✔
47
  ;(pair as any).pair = true
9,644✔
48
  return pair
9,644✔
49
}
50

51
/**
52
 * Check if a value is an improper list.
53
 * We force an improper list to be an array of two elements.
54
 * @param value
55
 * @returns
56
 */
57
export function isImproperList(value: any): value is Pair<any, any> {
80✔
58
  if (value === null) {
27,428!
NEW
59
    return false
×
60
  }
61
  return Array.isArray(value) && value.length === 2 && !isList(value[1])
27,428✔
62
}
63

64
/**
65
 * Check if a value is a pair.
66
 * @param value
67
 * @returns
68
 */
69
export function isPair(value: any): value is Pair<any, any> {
80✔
70
  return Array.isArray(value) && value.length === 2
47✔
71
}
72

73
/**
74
 * Convert an improper list into an array and a terminator.
75
 * @param value
76
 * @returns
77
 */
78
export function flattenImproperList(value: any): [any[], any] {
80✔
79
  let items = []
470✔
80
  let working = value
470✔
81
  while (working instanceof Array && working.length === 2) {
470✔
82
    items.push(working[0])
1,457✔
83
    working = working[1]
1,457✔
84
  }
85
  return [items, working]
470✔
86
}
87

88
/**
89
 * Get the length of an improper list.
90
 * @param value
91
 * @returns
92
 */
93
export function improperListLength(value: any): number {
80✔
NEW
94
  let length = 0
×
NEW
95
  let working = value
×
NEW
96
  while (isPair(working)) {
×
NEW
97
    length++
×
NEW
98
    working = working[1]
×
99
  }
NEW
100
  return length
×
101
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc