UNPKG

1.59 kBPlain TextView Raw
1import { expect } from "chai";
2import { BasicTests } from "../../test/helper/Basic.js";
3import { connectFrom, connectTo } from "../../test/helper/Connect.js";
4import { ConstantOutput } from "../../test/helper/ConstantOutput.js";
5import { Scale } from "./Scale.js";
6import { Signal } from "./Signal.js";
7
8describe("Scale", () => {
9 BasicTests(Scale);
10
11 context("Scaling", () => {
12 it("handles input and output connections", () => {
13 const scale = new Scale({ min: 0, max: 100 });
14 connectFrom().connect(scale);
15 scale.connect(connectTo());
16 scale.dispose();
17 });
18
19 it("can set the min and max values", () => {
20 const scale = new Scale({ min: 0, max: 100 });
21 scale.min = -0.01;
22 expect(scale.min).to.be.closeTo(-0.01, 0.001);
23 scale.max = 1000;
24 expect(scale.max).to.be.closeTo(1000, 0.001);
25 scale.dispose();
26 });
27
28 it("scales to the min when the input is 0", () => {
29 return ConstantOutput(() => {
30 const signal = new Signal(0);
31 const scale = new Scale({ min: -10, max: 8 });
32 signal.connect(scale);
33 scale.toDestination();
34 }, -10);
35 });
36
37 it("scales to the max when the input is 1", () => {
38 return ConstantOutput(() => {
39 const signal = new Signal(1);
40 const scale = new Scale(-10, 0);
41 scale.max = 8;
42 signal.connect(scale);
43 scale.toDestination();
44 }, 8);
45 });
46
47 it("scales an input of 0.5 to 15 (10, 20)", () => {
48 return ConstantOutput(() => {
49 const signal = new Signal(0.5);
50 const scale = new Scale({ min: 10, max: 20 });
51 signal.connect(scale);
52 scale.toDestination();
53 }, 15);
54 });
55 });
56});