/*
 * 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 DislikeAnalyzerTest : McuTestCase {
	private const int[] bile_colors = {
		(int) 0xff95884bu,
		(int) 0xff716b40u,
		(int) 0xffb08e00u,
		(int) 0xff4c4308u,
		(int) 0xff464521u,
	};

	public DislikeAnalyzerTest() {
		base("dislike_analyzer");
		add_test("monk_skin_tone_scale_colors", test_monk_skin_tone_scale_colors);
		add_test("bile_colors_disliked", test_bile_colors_disliked);
		add_test("bile_colors_become_likeable", test_bile_colors_become_likeable);
		add_test("tone_67_not_disliked", test_tone_67_not_disliked);
	}

	public override void set_up() {}

	public void test_monk_skin_tone_scale_colors() {
		var monk_skin_tones = new int[] {
			(int) 0xfff6ede4u,
			(int) 0xfff3e7dbu,
			(int) 0xfff7ead0u,
			(int) 0xffeadabau,
			(int) 0xffd7bd96u,
			(int) 0xffa07e56u,
			(int) 0xff825c43u,
			(int) 0xff604134u,
			(int) 0xff3a312au,
			(int) 0xff292420u
		};


		foreach (int tone in monk_skin_tones) {
			var hct = Hct.from_int(tone);
			var answer = DislikeAnalyzer.is_disliked(hct);

			McuAssert.false(answer);
		}
	}

	public void test_bile_colors_disliked() {
		foreach (int color in bile_colors) {
			var hct = Hct.from_int(color);
			var answer = DislikeAnalyzer.is_disliked(hct);

			McuAssert.true(answer);
		}
	}

	public void test_bile_colors_become_likeable() {
		foreach (int color in bile_colors) {
			var hct = Hct.from_int(color);
			var disliked = DislikeAnalyzer.is_disliked(hct);

			McuAssert.true(disliked);

			var answer = DislikeAnalyzer.fix_if_disliked(hct);

			McuAssert.false(DislikeAnalyzer.is_disliked(answer));
		}
	}

	public void test_tone_67_not_disliked() {
		var color = Hct.from(100, 50, 67);

		var disliked = DislikeAnalyzer.is_disliked(color);

		McuAssert.false(disliked);

		var answer = DislikeAnalyzer.fix_if_disliked(color);

		McuAssert.ints_equal(answer.to_int(), color.to_int());
	}

	public override void tear_down() {}
}
