/*
 * 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 QuantizeWsmeansTest : McuTestCase {
	private const int red = (int) 0xffff0000u;
	private const int green = (int) 0xff00ff00u;
	private const int blue = (int) 0xff0000ffu;
	private const int white = (int) 0xffffffffu;
	private const int random = (int) 0xff426088u;
	private const int max_colors = 256;

	public QuantizeWsmeansTest () {
		base ("quantize_wsmeans");
		add_test ("random", test_1_random);
		add_test ("red", test_1_red);
		add_test ("green", test_1_green);
		add_test ("blue", test_1_blue);
		add_test ("5_blue", test_5_blue);
	}

	public override void set_up () {}

	public void test_1_random () {
		var result = QuantizerWsmeans.quantize (new int[] { (int) 0xff141216u }, new int[] {}, max_colors);
		var answer = result.get_keys_as_array ();

		McuAssert.uints_equal (answer[0], 0xff141216u);
	}

	public void test_1_red () {
		var result = QuantizerWsmeans.quantize (new int[] { red }, new int[] {}, max_colors);
		var answer = result.get_keys_as_array ();

		McuAssert.uints_equal (answer.length, 1);
		McuAssert.uints_equal (answer[0], red);
	}

	public void test_1_green () {
		var result = QuantizerWsmeans.quantize (new int[] { green }, new int[] {}, max_colors);
		var answer = result.get_keys_as_array ();

		McuAssert.uints_equal (answer.length, 1);
		McuAssert.uints_equal (answer[0], green);
	}

	public void test_1_blue () {
		var result = QuantizerWsmeans.quantize (new int[] { blue }, new int[] {}, max_colors);
		var answer = result.get_keys_as_array ();

		McuAssert.uints_equal (answer.length, 1);
		McuAssert.uints_equal (answer[0], blue);
	}

	public void test_5_blue () {
		var result = QuantizerWsmeans.quantize (new int[] { blue, blue, blue, blue, blue }, new int[] {}, max_colors);
		var answer = result.get_keys_as_array ();

		McuAssert.uints_equal (answer.length, 1);
		McuAssert.uints_equal (answer[0], blue);
	}

	public override void tear_down () {}
}
