/*
 * 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 TemperatureCacheTest : McuTestCase {
	private sealed Hct blue = Hct.from_int((int) 0xff0000ffu);
	private sealed Hct red = Hct.from_int((int) 0xffff0000u);
	private sealed Hct green = Hct.from_int((int) 0xff00ff00u);
	private sealed Hct white = Hct.from_int((int) 0xffffffffu);
	private sealed Hct black = Hct.from_int((int) 0xff000000u);

	public TemperatureCacheTest() {
		base("temperature_cache");
		add_test("raw_temperature", test_raw_temperature);
		add_test("relative_temperature", test_relative_temperature);
		add_test("complement", test_complement);
		add_test("analogous", test_analogous);
	}

	public override void set_up() {}

	public void test_raw_temperature() {
		var blue_temp = TemperatureCache.raw_temperature(blue);
		var red_temp = TemperatureCache.raw_temperature(red);
		var green_temp = TemperatureCache.raw_temperature(green);
		var white_temp = TemperatureCache.raw_temperature(white);
		var black_temp = TemperatureCache.raw_temperature(black);

		McuAssert.doubles_equal(blue_temp, -1.393);
		McuAssert.doubles_equal(red_temp, 2.351);
		McuAssert.doubles_equal(green_temp, -0.267);
		McuAssert.doubles_equal(white_temp, -0.5);
		McuAssert.doubles_equal(black_temp, -0.5);
	}

	public void test_relative_temperature() {
		var blue_temp = new TemperatureCache(blue).get_relative_temperature(blue);
		var red_temp = new TemperatureCache(red).get_relative_temperature(red);
		var green_temp = new TemperatureCache(green).get_relative_temperature(green);
		var white_temp = new TemperatureCache(white).get_relative_temperature(white);
		var black_temp = new TemperatureCache(black).get_relative_temperature(black);

		McuAssert.doubles_equal(blue_temp, 0.0);
		McuAssert.doubles_equal(red_temp, 1.0);
		McuAssert.doubles_equal(green_temp, 0.467);
		McuAssert.doubles_equal(white_temp, 0.5);
		McuAssert.doubles_equal(black_temp, 0.5);
	}

	public void test_complement() {
		var blue_complement = new TemperatureCache(blue).get_complement().to_int();
		var red_complement = new TemperatureCache(red).get_complement().to_int();
		var green_complement = new TemperatureCache(green).get_complement().to_int();
		var white_complement = new TemperatureCache(white).get_complement().to_int();
		var black_complement = new TemperatureCache(black).get_complement().to_int();

		McuAssert.int_and_uint_equal(blue_complement, 0xff9d0002u);
		McuAssert.int_and_uint_equal(red_complement, 0xff007bfcu);
		McuAssert.int_and_uint_equal(green_complement, 0xffffd2c9u);
		McuAssert.int_and_uint_equal(white_complement, 0xffffffffu);
		McuAssert.int_and_uint_equal(black_complement, 0xff000000u);
	}

	public void test_analogous() {
		var blue_analogous = new TemperatureCache(blue).get_analogous_colors();
		var red_analogous = new TemperatureCache(red).get_analogous_colors();
		var green_analogous = new TemperatureCache(green).get_analogous_colors();
		var white_analogous = new TemperatureCache(white).get_analogous_colors();
		var black_analogous = new TemperatureCache(black).get_analogous_colors();

		McuAssert.int_and_uint_equal(blue_analogous[0].to_int(), 0xff00590cu);
		McuAssert.int_and_uint_equal(blue_analogous[1].to_int(), 0xff00564eu);
		McuAssert.int_and_uint_equal(blue_analogous[2].to_int(), 0xff0000ffu);
		McuAssert.int_and_uint_equal(blue_analogous[3].to_int(), 0xff6700ccu);
		McuAssert.int_and_uint_equal(blue_analogous[4].to_int(), 0xff81009fu);

		McuAssert.int_and_uint_equal(red_analogous[0].to_int(), 0xfff60082u);
		McuAssert.int_and_uint_equal(red_analogous[1].to_int(), 0xfffc004cu);
		McuAssert.int_and_uint_equal(red_analogous[2].to_int(), 0xffff0000u);
		McuAssert.int_and_uint_equal(red_analogous[3].to_int(), 0xffd95500u);
		McuAssert.int_and_uint_equal(red_analogous[4].to_int(), 0xffaf7200u);

		McuAssert.int_and_uint_equal(green_analogous[0].to_int(), 0xffcee900u);
		McuAssert.int_and_uint_equal(green_analogous[1].to_int(), 0xff92f500u);
		McuAssert.int_and_uint_equal(green_analogous[2].to_int(), 0xff00ff00u);
		McuAssert.int_and_uint_equal(green_analogous[3].to_int(), 0xff00fd6fu);
		McuAssert.int_and_uint_equal(green_analogous[4].to_int(), 0xff00fab3u);

		McuAssert.int_and_uint_equal(black_analogous[0].to_int(), 0xff000000u);
		McuAssert.int_and_uint_equal(black_analogous[1].to_int(), 0xff000000u);
		McuAssert.int_and_uint_equal(black_analogous[2].to_int(), 0xff000000u);
		McuAssert.int_and_uint_equal(black_analogous[3].to_int(), 0xff000000u);
		McuAssert.int_and_uint_equal(black_analogous[4].to_int(), 0xff000000u);

		McuAssert.int_and_uint_equal(white_analogous[0].to_int(), 0xffffffffu);
		McuAssert.int_and_uint_equal(white_analogous[1].to_int(), 0xffffffffu);
		McuAssert.int_and_uint_equal(white_analogous[2].to_int(), 0xffffffffu);
		McuAssert.int_and_uint_equal(white_analogous[3].to_int(), 0xffffffffu);
		McuAssert.int_and_uint_equal(white_analogous[4].to_int(), 0xffffffffu);
	}

	public override void tear_down() {}
}
