/*
 * 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 Cam16Test : McuTestCase {
	public Cam16Test() {
		base("cam16");
		add_test("cam16_1", test_cam16_1);
		add_test("cam16_2", test_cam16_2);
		add_test("cam16_3", test_cam16_3);
		add_test("cam16_4", test_cam16_4);
		add_test("cam16_5", test_cam16_5);
		add_test("cam16_6", test_cam16_6);
		add_test("cam16_7", test_cam16_7);
		add_test("cam16_8", test_cam16_8);
		add_test("cam16_9", test_cam16_9);
		add_test("cam16_10", test_cam16_10);
	}

	public override void set_up() {}

	public void test_cam16_1() {
		var result = Cam16.from_int((int) 1151024110);

		McuAssert.doubles_equal(result.hue, 311.42806917590127, 1e-7);
		McuAssert.doubles_equal(result.j, 39.80957637025326, 1e-7);
		McuAssert.doubles_equal(result.q, 98.12583617460575, 1e-7);
		McuAssert.doubles_equal(result.m, 64.10143150621671, 1e-7);
		McuAssert.doubles_equal(result.s, 80.82434221770161, 1e-7);
		McuAssert.doubles_equal(result.jstar, 52.927210914635715, 1e-7);
		McuAssert.doubles_equal(result.astar, 26.14144025259719, 1e-7);
		McuAssert.doubles_equal(result.bstar, -29.622376253821233, 1e-7);
	}

	public void test_cam16_2() {
		var result = Cam16.from_int((int) 2599766946);

		McuAssert.doubles_equal(result.hue, 355.0503461678604, 1e-7);
		McuAssert.doubles_equal(result.j, 52.56866623390567, 1e-7);
		McuAssert.doubles_equal(result.q, 112.75948188554017, 1e-7);
		McuAssert.doubles_equal(result.m, 64.2339418261725, 1e-7);
		McuAssert.doubles_equal(result.s, 75.4754569748874, 1e-7);
		McuAssert.doubles_equal(result.jstar, 65.32748230521139, 1e-7);
		McuAssert.doubles_equal(result.astar, 39.413992608446186, 1e-7);
		McuAssert.doubles_equal(result.bstar, -3.413381791164169, 1e-7);
	}

	public void test_cam16_3() {
		var result = Cam16.from_int((int) 207007830);

		McuAssert.doubles_equal(result.hue, 145.62456894249067, 1e-7);
		McuAssert.doubles_equal(result.j, 53.54270205682524, 1e-7);
		McuAssert.doubles_equal(result.q, 113.79933774011006, 1e-7);
		McuAssert.doubles_equal(result.m, 45.67944977111023, 1e-7);
		McuAssert.doubles_equal(result.s, 63.35641059229854, 1e-7);
		McuAssert.doubles_equal(result.jstar, 66.20793233348957, 1e-7);
		McuAssert.doubles_equal(result.astar, -25.83510432830831, 1e-7);
		McuAssert.doubles_equal(result.bstar, 17.67339768662175, 1e-7);
	}

	public void test_cam16_4() {
		var result = Cam16.from_int((int) 2178068049);

		McuAssert.doubles_equal(result.hue, 89.18218954198817, 1e-7);
		McuAssert.doubles_equal(result.j, 64.64864806089051, 1e-7);
		McuAssert.doubles_equal(result.q, 125.04585955071941, 1e-7);
		McuAssert.doubles_equal(result.m, 31.023158944993195, 1e-7);
		McuAssert.doubles_equal(result.s, 49.809060584658496, 1e-7);
		McuAssert.doubles_equal(result.jstar, 75.66239905009027, 1e-7);
		McuAssert.doubles_equal(result.astar, 0.3348706268561027, 1e-7);
		McuAssert.doubles_equal(result.bstar, 23.45943416825876, 1e-7);
	}

	public void test_cam16_5() {
		var result = Cam16.from_int((int) 2293293753);

		McuAssert.doubles_equal(result.hue, 154.90292039856698, 1e-7);
		McuAssert.doubles_equal(result.j, 79.40954826675019, 1e-7);
		McuAssert.doubles_equal(result.q, 138.58810463022758, 1e-7);
		McuAssert.doubles_equal(result.m, 24.01419462632291, 1e-7);
		McuAssert.doubles_equal(result.s, 41.62660916534058, 1e-7);
		McuAssert.doubles_equal(result.jstar, 86.76592929927428, 1e-7);
		McuAssert.doubles_equal(result.astar, -17.343486416766375, 1e-7);
		McuAssert.doubles_equal(result.bstar, 8.123204738848699, 1e-7);
	}

	public void test_cam16_6() {
		var result = Cam16.from_int((int) 2127352753);

		// New values from Java impl
		McuAssert.doubles_equal(result.hue, 124.27447074214348, 1e-7);
		McuAssert.doubles_equal(result.j, 77.23107774663454, 1e-7);
		McuAssert.doubles_equal(result.q, 136.67391668157194, 1e-7);
		McuAssert.doubles_equal(result.m, 13.02024235353401, 1e-7);
		McuAssert.doubles_equal(result.s, 30.86503074651844, 1e-7);
		McuAssert.doubles_equal(result.jstar, 85.22091200460922, 1e-7);
		McuAssert.doubles_equal(result.astar, -6.42067037982892, 1e-7);
		McuAssert.doubles_equal(result.bstar, 9.42136549661547, 1e-7);
	}

	public void test_cam16_7() {
		var result = Cam16.from_int((int) 2692552334);

		McuAssert.doubles_equal(result.hue, 327.9022451708669, 1e-7);
		McuAssert.doubles_equal(result.j, 25.207401197509327, 1e-7);
		McuAssert.doubles_equal(result.q, 78.0824855218106, 1e-7);
		McuAssert.doubles_equal(result.m, 53.16273184281286, 1e-7);
		McuAssert.doubles_equal(result.s, 82.51384599304502, 1e-7);
		McuAssert.doubles_equal(result.jstar, 36.425276182524954, 1e-7);
		McuAssert.doubles_equal(result.astar, 29.499403055932383, 1e-7);
		McuAssert.doubles_equal(result.bstar, -18.50332986780255, 1e-7);
	}

	public void test_cam16_8() {
		var result = Cam16.from_int((int) 481692528);

		McuAssert.doubles_equal(result.hue, 355.279570048603, 1e-7);
		McuAssert.doubles_equal(result.j, 33.2614419664756, 1e-7);
		McuAssert.doubles_equal(result.q, 89.69332605634818, 1e-7);
		McuAssert.doubles_equal(result.m, 64.28874467824023, 1e-7);
		McuAssert.doubles_equal(result.s, 84.6617825549819, 1e-7);
		McuAssert.doubles_equal(result.jstar, 45.865567063105644, 1e-7);
		McuAssert.doubles_equal(result.astar, 39.449488663086846, 1e-7);
		McuAssert.doubles_equal(result.bstar, -3.257500355999049, 1e-7);
	}

	public void test_cam16_9() {
		var result = Cam16.from_int((int) 1073904100);

		McuAssert.doubles_equal(result.hue, 261.1968416808902, 1e-7);
		McuAssert.doubles_equal(result.j, 40.7183615122085, 1e-7);
		McuAssert.doubles_equal(result.q, 99.23953929867855, 1e-7);
		McuAssert.doubles_equal(result.m, 49.66881860103603, 1e-7);
		McuAssert.doubles_equal(result.s, 70.74561810312906, 1e-7);
		McuAssert.doubles_equal(result.jstar, 53.86745346363419, 1e-7);
		McuAssert.doubles_equal(result.astar, -5.083026592209834, 1e-7);
		McuAssert.doubles_equal(result.bstar, -32.82238686945024, 1e-7);
	}

	public void test_cam16_10() {
		var result = Cam16.from_int((int) 3734873206);

		McuAssert.doubles_equal(result.hue, 119.84832142132542, 1e-7);
		McuAssert.doubles_equal(result.j, 56.17844931089786, 1e-7);
		McuAssert.doubles_equal(result.q, 116.56669043770763, 1e-7);
		McuAssert.doubles_equal(result.m, 17.906925043592874, 1e-7);
		McuAssert.doubles_equal(result.s, 39.19433269789186, 1e-7);
		McuAssert.doubles_equal(result.jstar, 68.547225856322, 1e-7);
		McuAssert.doubles_equal(result.astar, -7.47360894560527, 1e-7);
		McuAssert.doubles_equal(result.bstar, 13.024174399350978, 1e-7);
	}

	public override void tear_down() {}
}
