Matematicheskiye_obosnovani.../lab1/convert.test.js
2025-01-29 16:04:11 +03:00

34 lines
1.8 KiB
JavaScript

import { Num } from "./index.js"
for (let i = 0; i < 0xFFFF; i++) {
const str2 = `0b${i.toString(2).toUpperCase()}`;
const str8 = `0o${i.toString(8).toUpperCase()}`;
const str16 = `0x${i.toString(16).toUpperCase()}`;
const str10 = i.toString(10).toUpperCase();
const t2 = Num.parse(str2);
const t8 = Num.parse(str8);
const t16 = Num.parse(str16);
const t10 = Num.parse(str10);
if (t2.as(2).toString() !== str2) throw new Error(`${str2}:${t2.as(2).toString()}`);
if (t2.as(8).toString() !== str8) throw new Error(`${str2}:${t2.as(8).toString()}`);
if (t2.as(16).toString() !== str16) throw new Error(`${str2}:${t2.as(16).toString()}`);
if (t2.as(10).toString() !== str10) throw new Error(`${str2}:${t2.as(10).toString()}`);
if (t8.as(2).toString() !== str2) throw new Error(`${str2}:${t8.as(2).toString()}`);
if (t8.as(8).toString() !== str8) throw new Error(`${str2}:${t8.as(8).toString()}`);
if (t8.as(16).toString() !== str16) throw new Error(`${str2}:${t8.as(16).toString()}`);
if (t8.as(10).toString() !== str10) throw new Error(`${str2}:${t8.as(10).toString()}`);
if (t16.as(2).toString() !== str2) throw new Error(`${str2}:${t16.as(2).toString()}`);
if (t16.as(8).toString() !== str8) throw new Error(`${str2}:${t16.as(8).toString()}`);
if (t16.as(16).toString() !== str16) throw new Error(`${str2}:${t16.as(16).toString()}`);
if (t16.as(10).toString() !== str10) throw new Error(`${str2}:${t16.as(10).toString()}`);
if (t10.as(2).toString() !== str2) throw new Error(`${str2}:${t10.as(2).toString()}`);
if (t10.as(8).toString() !== str8) throw new Error(`${str2}:${t10.as(8).toString()}`);
if (t10.as(16).toString() !== str16) throw new Error(`${str2}:${t10.as(16).toString()}`);
if (t10.as(10).toString() !== str10) throw new Error(`${str2}:${t10.as(10).toString()}`);
}