package org.mammon.math;

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

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

public class ZElementTest {

	private FiniteField<Z> field;
	private FiniteField.Element<Z> zero;
	private FiniteField.Element<Z> one;

	@Before
	public void createFiniteField() {
		field = new Z(11);
		zero = field.getZero();
		one = field.getOne();
	}

	public void zeroShouldDifferFromOne() {
		assertFalse(one.equals(zero));
	}

	@Test
	public void zeroShouldBeIdentityForAddition() {
		assertEquals(zero, zero.add(zero));
		assertEquals(one, one.add(zero));
	}

	@Test
	public void oneShouldBeIdentityForMulitplication() {
		assertEquals(zero, zero.multiply(one));
		assertEquals(one, one.multiply(one));
	}

	@SuppressWarnings("unchecked")
	@Test
	public void oppositesShouldSumToZero() {
		for (FiniteField.Element<Z> element : new FiniteField.Element[] { zero, one }) {
			assertEquals(zero, element.add(element.getOpposite()));
		}
	}

	@SuppressWarnings("unchecked")
	@Test
	public void inversesShouldMultiplyToOne() {
		for (FiniteField.Element<Z> element : new FiniteField.Element[] { one }) {
			assertEquals(one, element.multiply(element.getInverse()));
		}
	}
}

@@ -776,47 +776,15 @@
 %09%7D%0A%0A
-%09@SuppressWarnings(%22unchecked%22)%0A
 %09@Test%0A
+
 %09pub
@@ -975,40 +975,8 @@
 %09%7D%0A%0A
-%09@SuppressWarnings(%22unchecked%22)%0A
 %09@Te
@@ -1162,17 +1162,206 @@
 se()));%0A
-
 %09%09%7D%0A%09%7D
+%0A%0A%09@Test%0A%09public void additionShouldHaveOrderQ() %7B%0A%09%09FiniteField.Element%3CZ%3E result = zero;%0A%09%09for (int i = 0; i %3C 11; i++) %7B%0A%09%09%09result = result.add(one);%0A%09%09%7D%0A%09%09assertEquals(zero, result);%0A%09%7D
 %0A%7D%0A

Order of addition