<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


/**
 * implement method:
 * public static int Lab03.dominatingElement(int[] a)
 * which returns value of the dominating element (with more then n/2 occurrences)
 * or returns -1 if it does not exist
 * note: you can assume that int[] a has only non-negative elements
 */
public class Lab03DominatingElementTest {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testSimple() {
		assertEquals(
				42, 
				run(new int[]{1,42,2,42,42,3,42})
		);
	}

	@Test
	public void testNoDominatingElement() {
		assertEquals(
				-1, 
				run(new int[]{1,2,3})
		);
		assertEquals(
				-1, 
				run(new int[]{1,3,2,2})
		);
		assertEquals(
				-1, 
				run(new int[]{1,2,3,2})
		);
	}

	@Test
	public void testEmpty() {
		assertEquals(
				-1, 
				run(new int[]{})
		);
	}

	@Test
	public void testAllEquals() {
		assertEquals(
				1, 
				run(new int[]{1,1,1,1})
		);
		assertEquals(
				1, 
				run(new int[]{1,1,1,1,1})
		);
	}


	int run(int[] a) {
		return Lab03.dominatingElement(a);
	}
	
	
}
</pre></body></html>