mirror of https://github.com/XS-MLVP/picker.git
35 lines
1.1 KiB
Java
35 lines
1.1 KiB
Java
package com.ut;
|
|
|
|
import java.math.BigInteger;
|
|
|
|
// import the generated UT class
|
|
import com.ut.Adder.UT_Adder;
|
|
|
|
public class example {
|
|
static public void main(String[] args){
|
|
UT_Adder adder = new UT_Adder();
|
|
for(int i=0; i<10000; i++){
|
|
int N = 1000000;
|
|
long a = (long) (Math.random() * N);
|
|
long b = (long) (Math.random() * N);
|
|
boolean c = (Math.random() * N) > 50; // just for testing boolean type
|
|
// set inputs
|
|
adder.a.Set(a);
|
|
adder.b.Set(b);
|
|
adder.cin.Set(c);
|
|
// step
|
|
adder.Step();
|
|
// reference model
|
|
long sum = a + b;
|
|
boolean carry = sum < a ? true : false;
|
|
sum += c ? 1 : 0;
|
|
carry = carry || sum < (c ? 1 : 0);
|
|
// assert
|
|
assert adder.sum.U().longValue() == sum : "sum mismatch: " + adder.sum.U() + " != " + sum;
|
|
assert adder.cout.U().intValue() == (carry ? 1 : 0) : "carry mismatch: " + adder.cout.U() + " != " + carry;
|
|
}
|
|
System.out.println("Java tests passed");
|
|
adder.Finish();
|
|
}
|
|
}
|