<commit_before>import { expect } from "chai";
import { BasicTests } from "test/helper/Basic";
import { connectFrom, connectTo } from "test/helper/Connect";
import { ConstantOutput } from "test/helper/ConstantOutput";
import { Offline } from "test/helper/Offline";
import { Gain } from "../core/context/Gain";
import { Signal } from "./Signal";

describe("Signal", () => {

	BasicTests(Signal);

	context("Signal Rate Value", () => {

		it("handles input and output connections", () => {
			const signal = new Signal();
			connectFrom().connect(signal);
			signal.connect(connectTo());
			signal.dispose();
		});

		it("can be created with an options object", () => {
			const signal = new Signal({
				units: "positive",
				value: 0.2,
			});
			expect(signal.value).to.be.closeTo(0.2, 0.001);
			expect(signal.units).to.equal("positive");
			signal.dispose();
		});

		it("can start with a value initially", () => {
			const signal = new Signal(2);
			expect(signal.value).to.equal(2);
			signal.dispose();
		});

		it("can set a value", () => {
			const signal = new Signal(0);
			signal.value = 10;
			expect(signal.value).to.equal(10);
			signal.dispose();
		});

		it("outputs a constant signal", () => {
			return ConstantOutput((context) => {
				const sig = new Signal(2.5).toMaster();
			}, 2.5);
		});

		it("takes on another signal's value when connected", () => {
			return ConstantOutput((context) => {
				const sigA = new Signal(1).toMaster();
				const sigB = new Signal(3);
				sigB.connect(sigA);
			}, 3);
		});

		it("takes the first signals value when many values are chained", () => {
			return ConstantOutput((context) => {
				const sigA = new Signal(3).toMaster();
				const sigB = new Signal(1).connect(sigA);
				const sigC = new Signal(2).connect(sigB);
			}, 2);
		});
	});

	context("Scheduling", () => {

		it("can be scheduled to set a value in the future", async () => {
			const buffer = await Offline((context) => {
					const sig = new Signal(0).toMaster();
					sig.setValueAtTime(2, 0.2);
			}, 0.25);
			expect(buffer.getValueAtTime(0)).to.be.closeTo(0, 0.001);
			expect(buffer.getValueAtTime(0.19)).to.be.closeTo(0, 0.001);
			expect(buffer.getValueAtTime(0.2)).to.be.closeTo(2, 0.001);
			expect(buffer.getValueAtTime(0.24)).to.be.closeTo(2, 0.001);
		});

		it("can linear ramp from the current value to another value in the future", async () => {
			const buffer = await Offline(context => {
				const sig = new Signal(0).toMaster();<commit_msg>adding a short timeout bc Canary is running out of contexts<commit_after>import { expect } from "chai";
import { BasicTests } from "test/helper/Basic";
import { connectFrom, connectTo } from "test/helper/Connect";
import { ConstantOutput } from "test/helper/ConstantOutput";
import { Offline } from "test/helper/Offline";
import { Gain } from "../core/context/Gain";
import { Signal } from "./Signal";

describe("Signal", () => {

	BasicTests(Signal);

	context("Signal Rate Value", () => {

		it("handles input and output connections", () => {
			const signal = new Signal();
			connectFrom().connect(signal);
			signal.connect(connectTo());
			signal.dispose();
		});

		it("can be created with an options object", () => {
			const signal = new Signal({
				units: "positive",
				value: 0.2,
			});
			expect(signal.value).to.be.closeTo(0.2, 0.001);
			expect(signal.units).to.equal("positive");
			signal.dispose();
		});

		it("can start with a value initially", () => {
			const signal = new Signal(2);
			expect(signal.value).to.equal(2);
			signal.dispose();
		});

		it("can set a value", () => {
			const signal = new Signal(0);
			signal.value = 10;
			expect(signal.value).to.equal(10);
			signal.dispose();
		});

		it("outputs a constant signal", () => {
			return ConstantOutput((context) => {
				const sig = new Signal(2.5).toMaster();
			}, 2.5);
		});

		it("takes on another signal's value when connected", () => {
			return ConstantOutput((context) => {
				const sigA = new Signal(1).toMaster();
				const sigB = new Signal(3);
				sigB.connect(sigA);
			}, 3);
		});

		it("takes the first signals value when many values are chained", () => {
			return ConstantOutput((context) => {
				const sigA = new Signal(3).toMaster();
				const sigB = new Signal(1).connect(sigA);
				const sigC = new Signal(2).connect(sigB);
			}, 2);
		});
	});

	context("Scheduling", () => {

		afterEach(done => {
			setTimeout(() => done(), 100);
		});

		it("can be scheduled to set a value in the future", async () => {
			const buffer = await Offline((context) => {
					const sig = new Signal(0).toMaster();
					sig.setValueAtTime(2, 0.2);
			}, 0.25);
			expect(buffer.getValueAtTime(0)).to.be.closeTo(0, 0.001);
			expect(buffer.getValueAtTime(0.19)).to.be.closeTo(0, 0.001);
			expect(buffer.getValueAtTime(0.2)).to.be.closeTo(2, 0.001);
			expect(buffer.getValueAtTime(0.24)).to.be.closeTo(2, 0.001);
		});

		it("can linear ramp from the current value to another value in the future", async () => {
			const buffer = await Offline(context => {
				const sig = new Signal(0).toMaster();
{'fraction_non_alphanumeric': 0.18176459029278838, 'fraction_numerical': 0.025348791511102378, 'mean_word_length': 3.5405887600356825, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4500895', 'n_tokens_mistral': 1992, 'n_tokens_neox': 1644, 'n_words': 407}