/*******************************************************************************
 * Copyright (c) 2016 Microsoft Research. All rights reserved. 
 *
 * The MIT License (MIT)
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy 
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is furnished to do
 * so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software. 
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * Contributors:
 *   Markus Alexander Kuppe - initial API and implementation
 ******************************************************************************/
package tlc2.tool.fp;

import java.io.IOException;

import org.junit.Assume;
import org.junit.Before;

import junit.framework.TestCase;
import util.TLCRuntime;

public class LongArrayTest extends TestCase {
	
	@Before
	public void setup() {
		Assume.assumeTrue(TLCRuntime.getInstance().getArchitecture() == TLCRuntime.ARCH.x86_64);
	}

	public void testGetAndSet() throws IOException {
		final int elements = 100;

		final LongArray array = new LongArray(elements);
		array.zeroMemory(1);
		
		for (long i = 0L; i < elements; i++) {
			assertEquals(0L, array.get(i));
		}

		
		for (long i = 0L; i < elements; i++) {
			array.set(i, i);
		}
		for (long i = 0L; i < elements; i++) {
			assertEquals(i, array.get(i));
		}

		
		for (long i = 0L; i < elements; i++) {
			array.set(i, Long.MAX_VALUE - i);
		}
		for (long i = 0L; i < elements; i++) {
			assertEquals(Long.MAX_VALUE - i, array.get(i));
		}
		

		for (long i = 0L; i < elements; i++) {
			array.set(i, Long.MIN_VALUE + i);
		}
		for (long i = 0L; i < elements; i++) {
			assertEquals(Long.MIN_VALUE + i, array.get(i));
		}
	}
	
	public void testOutOfRangePositive() throws IOException {
		final LongArray array = new LongArray(1);
		try {
			array.get(1);
		} catch (AssertionError e) {
			return;
		}
		fail();
	}
	
	public void testOutOfRangeNegative() throws IOException {
		final LongArray array = new LongArray(1);
		try {
			array.get(-1);
		} catch (AssertionError e) {
			return;
		}
		fail();
	}
	
	public void testGetAndTrySet() throws IOException {
		final int elements = 100;

		final LongArray array = new LongArray(elements);
		array.zeroMemory(1);
		
		// Assert zero successful
		for (long i = 0L; i < elements; i++) {
			assertEquals(0L, array.get(i));
		}

		// trySet linear elements.
		for (long i = 0L; i < elements; i++) {
			assertTrue(array.trySet(i, 0, i));
		}
		for (long i = 0L; i < elements; i++) {
			assertEquals(i, array.get(i));
		}

		// Replace with largest possible values
		for (long i = 0L; i < elements; i++) {
			array.trySet(i, i, Long.MAX_VALUE - i);
		}
		for (long i = 0L; i < elements; i++) {
			assertEquals(Long.MAX_VALUE - i, array.get(i));
		}
		

		// Replace with smallest possible values
		for (long i = 0L; i < elements; i++) {
			array.trySet(i, Long.MAX_VALUE - i, Long.MIN_VALUE + i);
		}
		for (long i = 0L; i < elements; i++) {
			assertEquals(Long.MIN_VALUE + i, array.get(i));
		}
	}
	
	public void testZeroMemory() throws IOException {
		for (int k = 1; k < 8; k++) {
			for (int i = 1; i < 128; i++) {
				final LongArray array = new LongArray(i);
				array.zeroMemory(k);
				for (int j = 0; i < j; i++) {
					assertEquals(0L, array.get(j));
				}
				for (int j = 0; i < j; i++) {
					array.set(j, -1L);
				}
			}
		}
	}
}

@@ -1427,16 +1427,99 @@
 ol.fp;%0A%0A
+import static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.fail;%0A%0A
 import j
@@ -1593,41 +1593,31 @@
 re;%0A
-%0A
 import 
+org.
 junit.
-framework.TestCase;
+Test;%0A
 %0Aimp
@@ -1669,25 +1669,8 @@
 est 
-extends TestCase 
 %7B%0A%09%0A
@@ -1796,16 +1796,23 @@
 4);%0A%09%7D%0A%0A
+%09@Test%0A
 %09public 
@@ -2548,32 +2548,39 @@
 t(i));%0A%09%09%7D%0A%09%7D%0A%09%0A
+%09@Test%0A
 %09public void tes
@@ -2744,32 +2744,39 @@
 %0A%09%09fail();%0A%09%7D%0A%09%0A
+%09@Test%0A
 %09public void tes
@@ -2945,24 +2945,31 @@
 ail();%0A%09%7D%0A%09%0A
+%09@Test%0A
 %09public void
@@ -3895,16 +3895,23 @@
 %09%7D%0A%09%7D%0A%09%0A
+%09@Test%0A
 %09public 

Convert to JUnit 4 test case to make @Before (Assume) work.