/*
 * 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 TonalPalettesTest : McuTestCase {
	public TonalPalettesTest () {
		base ("tonal_palettes");
		add_test ("tones_of_blue", test_tones_of_blue);
		add_test ("key_color_exact_chroma_available", test_key_color_exact_chroma_available);
		add_test ("key_color_unusually_high_chroma", test_key_color_unusually_high_chroma);
		add_test ("key_color_unusually_low_chroma", test_key_color_unusually_low_chroma);
	}

	public override void set_up () {}

	public void test_tones_of_blue () {
		var hct = Hct.from_int ((int) 0xff0000ffu);
		var answer = TonalPalette.from_hue_and_chroma (hct.hue, hct.chroma);

		McuAssert.int_and_uint_equal (answer.tone (0), 0xff000000u);
		McuAssert.int_and_uint_equal (answer.tone (10), 0xff00006eu);
		McuAssert.int_and_uint_equal (answer.tone (20), 0xff0001acu);
		McuAssert.int_and_uint_equal (answer.tone (30), 0xff0000efu);
		McuAssert.int_and_uint_equal (answer.tone (40), 0xff343dffu);
		McuAssert.int_and_uint_equal (answer.tone (50), 0xff5a64ffu);
		McuAssert.int_and_uint_equal (answer.tone (60), 0xff7c84ffu);
		McuAssert.int_and_uint_equal (answer.tone (70), 0xff9da3ffu);
		McuAssert.int_and_uint_equal (answer.tone (80), 0xffbec2ffu);
		McuAssert.int_and_uint_equal (answer.tone (90), 0xffe0e0ffu);
		McuAssert.int_and_uint_equal (answer.tone (95), 0xfff1efffu);
		McuAssert.int_and_uint_equal (answer.tone (99), 0xfffffbffu);
		McuAssert.int_and_uint_equal (answer.tone (100), 0xffffffffu);

		McuAssert.int_and_uint_equal (answer.tone (3), 0xff00003cu);
	}

	public void test_key_color_exact_chroma_available () {
		var palette = TonalPalette.from_hue_and_chroma (50.0, 60.0);
		var answer = palette.key_color;

		McuAssert.doubles_equal (answer.hue, 50.0, 10.0);
		McuAssert.doubles_equal (answer.chroma, 60.0, 0.5);
		McuAssert.true (answer.tone > 0 && answer.tone < 100);
	}

	public void test_key_color_unusually_high_chroma () {
		var palette = TonalPalette.from_hue_and_chroma (149.0, 200.0);
		var answer = palette.key_color;

		McuAssert.doubles_equal (answer.hue, 149.0, 10.0);
		McuAssert.double_greater_than_double (answer.chroma, 89.0);
		McuAssert.true (answer.tone > 0 && answer.tone < 100);
	}

	public void test_key_color_unusually_low_chroma () {
		var palette = TonalPalette.from_hue_and_chroma (50.0, 3.0);
		var answer = palette.key_color;

		McuAssert.doubles_equal (answer.hue, 50.0, 10.0);
		McuAssert.doubles_equal (answer.chroma, 3.0, 0.5);
		McuAssert.doubles_equal (answer.tone, 50.0, 0.5);
	}

	public override void tear_down () {}
}
