/*
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * ---------------------------------------------------------------------
 *
 * Portions of this file were modified and ported to Vala by Victor Vintorez in 2026.
 * These modifications are licensed under the European Union Public License (EUPL),
 * Version 1.2 or later. You may obtain a copy of the License at:
 * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
 */

using GLib;
using MaterialColorUtilities;

public class ContrastTest : McuTestCase {
	public ContrastTest() {
		base("contrast_tests");
		add_test("ratio_of_tones_out_of_bounds_input", test_ratio_of_tones_out_of_bounds_input);
		add_test("lighter_impossible_ratio_errors", test_lighter_impossible_ratio_errors);
		add_test("lighter_out_of_bounds_input_above_errors", test_lighter_out_of_bounds_input_above_errors);
		add_test("lighter_out_of_bounds_input_below_errors", test_lighter_out_of_bounds_input_below_errors);
		add_test("lighter_unsafe_returns_max_tone", test_lighter_unsafe_returns_max_tone);
		add_test("darker_impossible_ratio_errors", test_darker_impossible_ratio_errors);
		add_test("darker_out_of_bounds_input_above_errors", test_darker_out_of_bounds_input_above_errors);
		add_test("darker_out_of_bounds_input_below_errors", test_darker_out_of_bounds_input_below_errors);
	}

	public override void set_up() {}

	public void test_ratio_of_tones_out_of_bounds_input() {
		var ratio = Contrast.ratio_of_tones(-10.0, 110.0);

		// New value from Java impl, previously 21.0
		McuAssert.doubles_equal(ratio, 34.2043);
	}

	public void test_lighter_impossible_ratio_errors() {
		var tone = Contrast.lighter(90.0, 10.0);

		McuAssert.doubles_equal(tone, -1.0);
	}

	public void test_lighter_out_of_bounds_input_above_errors() {
		var tone = Contrast.lighter(110.0, 2.0);

		McuAssert.doubles_equal(tone, -1.0);
	}

	public void test_lighter_out_of_bounds_input_below_errors() {
		var tone = Contrast.lighter(-10.0, 2.0);

		McuAssert.doubles_equal(tone, -1.0);
	}

	public void test_lighter_unsafe_returns_max_tone() {
		var tone = Contrast.lighter_unsafe(100, 2);

		McuAssert.doubles_equal(tone, 100.0);
	}

	public void test_darker_impossible_ratio_errors() {
		var tone = Contrast.darker(10, 20);

		McuAssert.doubles_equal(tone, -1.0);
	}

	public void test_darker_out_of_bounds_input_above_errors() {
		var tone = Contrast.darker(110, 2);

		McuAssert.doubles_equal(tone, -1.0);
	}

	public void test_darker_out_of_bounds_input_below_errors() {
		var tone = Contrast.darker(-10, 2);

		McuAssert.doubles_equal(tone, -1.0);
	}

	public void test_darker_unsafe_returns_min_tone() {
		var tone = Contrast.darker_unsafe(0, 2);

		McuAssert.doubles_equal(tone, 0.0);
	}

	public override void tear_down() {}
}
