-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathaccumulator.test.js
46 lines (34 loc) · 1.77 KB
/
accumulator.test.js
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
46
/////////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2025 Garmin International, Inc.
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
// may not use this file except in compliance with the Flexible and Interoperable Data
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
import { describe, expect, test } from "vitest";
import Accumulator from "../src/accumulator.js";
describe("Accumulator Tests", () => {
test("Accumulates field", () => {
const accumulator = new Accumulator();
accumulator.createAccumulatedField(0, 0, 0);
expect(accumulator.accumulate(0, 0, 1, 8)).toBe(1);
expect(accumulator.accumulate(0, 0, 2, 8)).toBe(2);
expect(accumulator.accumulate(0, 0, 3, 8)).toBe(3);
expect(accumulator.accumulate(0, 0, 4, 8)).toBe(4);
});
test("Accumulates multiple fields independently", () => {
const accumulator = new Accumulator();
accumulator.createAccumulatedField(0, 0, 0);
expect(accumulator.accumulate(0, 0, 254, 8)).toBe(254);
accumulator.createAccumulatedField(1, 1, 0);
expect(accumulator.accumulate(1, 1, 2, 8)).toBe(2);
expect(accumulator.accumulate(0, 0, 0, 8)).toBe(256);
});
test("Accumulates when field rolls over", () => {
const accumulator = new Accumulator();
accumulator.createAccumulatedField(0, 0, 250);
expect(accumulator.accumulate(0, 0, 254, 8)).toBe(254);
expect(accumulator.accumulate(0, 0, 255, 8)).toBe(255);
expect(accumulator.accumulate(0, 0, 0, 8)).toBe(256);
expect(accumulator.accumulate(0, 0, 3, 8)).toBe(259);
});
});