mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-15 02:54:07 +00:00
utils/math: add crc32 function
This matches the STM32 hardware CRC.
This commit is contained in:
+14
-2
@@ -1,7 +1,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2020 The Pybricks Authors
|
||||
// Copyright (c) 2020-2022 The Pybricks Authors
|
||||
|
||||
import { fmod, sumComplement32, xor8 } from './math';
|
||||
import { crc32, fmod, sumComplement32, xor8 } from './math';
|
||||
|
||||
describe('fmod', () => {
|
||||
test('positive numbers', () => {
|
||||
@@ -22,6 +22,18 @@ describe('sumComplement32', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('crc32', () => {
|
||||
test('trivial', () => {
|
||||
expect(crc32([0])).toBe(0);
|
||||
});
|
||||
test('trivial2', () => {
|
||||
expect(crc32([0xffffffff])).toBe(0);
|
||||
});
|
||||
test('basic', () => {
|
||||
expect(crc32([1, 2, 3, 4, 5])).toBe(-2048796416);
|
||||
});
|
||||
});
|
||||
|
||||
describe('xor8', () => {
|
||||
test('basic', () => {
|
||||
expect(xor8([0])).toBe(0xff);
|
||||
|
||||
Reference in New Issue
Block a user