/*
 * Zorbage: an algebraic data hierarchy for use in numeric processing.
 *
 * Copyright (C) 2016-2019 Barry DeZonia
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package nom.bdezonia.zorbage.algorithm;

import static org.junit.Assert.assertEquals;

import java.math.BigDecimal;

import org.junit.Test;

import nom.bdezonia.zorbage.algebras.G;
import nom.bdezonia.zorbage.type.data.highprec.real.HighPrecisionMember;
import nom.bdezonia.zorbage.type.data.int8.SignedInt8Member;
import nom.bdezonia.zorbage.type.storage.Storage;
import nom.bdezonia.zorbage.type.storage.array.ArrayStorage;
import nom.bdezonia.zorbage.type.storage.datasource.IndexedDataSource;

/**
 * 
 * @author Barry DeZonia
 *
 */
public class TestScaleByHighPrec {

	@Test
	public void test1() {
		SignedInt8Member value = G.INT8.construct();
		IndexedDataSource<SignedInt8Member> bytes1 = ArrayStorage.allocateBytes(
				new byte[] {-128, -64, -36, -15, -2, -1, 0, 1, 2, 11, 27, 84, 100});
		IndexedDataSource<SignedInt8Member> bytes2 = Storage.allocate(bytes1.size(), value);
		HighPrecisionMember scale = new HighPrecisionMember(BigDecimal.valueOf(1.3));
		ScaleByHighPrec.compute(G.INT8, scale, bytes1, bytes2);
		bytes2.get(0, value);
		assertEquals((byte)(1.3*(-128)-0.5), value.v());
		bytes2.get(1, value);
		assertEquals((byte)(1.3*(-64)-0.5), value.v());
		bytes2.get(2, value);
		assertEquals((byte)(1.3*(-36)-0.5), value.v());
		bytes2.get(3, value);
		assertEquals((byte)(1.3*(-15)-0.5), value.v());
		bytes2.get(4, value);
		assertEquals((byte)(1.3*(-2)-0.5), value.v());
		bytes2.get(5, value);
		assertEquals((byte)(1.3*(-1)-0.5), value.v());
		bytes2.get(6, value);
		assertEquals((byte)(1.3*(0)), value.v());
		bytes2.get(7, value);
		assertEquals((byte)(1.3*(1)+0.5), value.v());
		bytes2.get(8, value);
		assertEquals((byte)(1.3*(2)+0.5), value.v());
		bytes2.get(9, value);
		assertEquals((byte)(1.3*(11)+0.5), value.v());
		bytes2.get(10, value);
		assertEquals((byte)(1.3*(27)+0.5), value.v());
		bytes2.get(11, value);
		assertEquals((byte)(1.3*(84)+0.5), value.v());
		bytes2.get(12, value);
		assertEquals((byte)(1.3*(100)+0.5), value.v());
	}
}

@@ -2504,20 +2504,16 @@
 3*(-128)
--0.5
 ), value
@@ -2574,20 +2574,16 @@
 .3*(-64)
--0.5
 ), value
@@ -2644,20 +2644,16 @@
 .3*(-36)
--0.5
 ), value
@@ -2714,20 +2714,16 @@
 .3*(-15)
--0.5
 ), value
@@ -2783,20 +2783,16 @@
 1.3*(-2)
--0.5
 ), value
@@ -2856,12 +2856,8 @@
 (-1)
--0.5
 ), v
@@ -2988,20 +2988,16 @@
 (1.3*(1)
-+0.5
 ), value
@@ -3056,20 +3056,16 @@
 (1.3*(2)
-+0.5
 ), value
@@ -3125,20 +3125,16 @@
 1.3*(11)
-+0.5
 ), value
@@ -3195,20 +3195,16 @@
 1.3*(27)
-+0.5
 ), value
@@ -3265,20 +3265,16 @@
 1.3*(84)
-+0.5
 ), value
@@ -3340,12 +3340,8 @@
 100)
-+0.5
 ), v

Fix a test so it behaves as new api expects