package de.lcag.common;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.HashMap;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class PositionOrderedMapTest {
	private PositionOrderedMap<String, String> testMap;

	@BeforeEach
	void setup() {
		testMap = new PositionOrderedMap<>();
		testMap.put("Audi", "Car");
		testMap.put("BMW", "luxory car");
		testMap.put("Boing", "Airplane");
		testMap.put("TV", "Device");
	}

	@Test
	void testGetPositionOfValue() {
		assertEquals(Integer.valueOf(0), testMap.getPositionOfValue("Car"));
		assertEquals(Integer.valueOf(3), testMap.getPositionOfValue("Device"));
	}

	@Test
	void testGetPositionOfKey() {
		System.out.println(testMap);
		assertEquals(Integer.valueOf(0), testMap.getPositionOfKey("Audi"));
		assertEquals(Integer.valueOf(3), testMap.getPositionOfKey("TV"));
	}

	@Test
	void testGetPositionOfLastElement() {
		assertEquals(3, testMap.getPositionOfLastElement());
	}

	@Test
	void testGetKeyByPosition() {
		assertEquals("BMW", testMap.getKeyByPosition(1));
		assertEquals("TV", testMap.getKeyByPosition(3));
	}

	@Test
	void testShiftPosition() {
		int newPosition = -1;

		assertThrows(IllegalArgumentException.class, () -> {
			testMap.shiftPosition(2);
		});

		testMap.shiftAllPositions(2);
		assertThrows(IllegalArgumentException.class, () -> {
			testMap.shiftPosition(2);
		});

		newPosition = testMap.shiftPosition(1);
		assertEquals(2, newPosition);

		System.out.println(testMap.toString());
	}

	@Test
	void testShiftPositionByKey() {
		testMap.shiftPositionByKey("Boing");
	}

	@Test
	void testShiftPositionByValue() {
		fail("Not yet implemented");
	}

	@Test
	void testShiftAllPositions() {
		fail("Not yet implemented");
	}

	@Test
	void testPutAllIntMapOfQextendsKQextendsV() {
		HashMap<String, String> m = new HashMap<>();
		m.put("A", "a1");
		m.put("B", "b1");

		testMap.putAll(m);

		assertEquals(Integer.valueOf(4), testMap.getPositionOfValue("a1"));
	}

	@Test
	void testGetInt() {
		fail("Not yet implemented");
	}

	@Test
	void testIndexOf() {
		fail("Not yet implemented");
	}

}
