Package hlcd.testing.optimizationTester
Class QuaternaryVectorMultiplicationTester
java.lang.Object
hlcd.testing.optimizationTester.QuaternaryVectorMultiplicationTester
Test the multiplication logic of two rows vectors being multiplied by each
other. The multiplication is done element-wise. There are two approaches:
the optimal approach which uses binary manipulation without a
loop, and the naive approach which uses a loop. It will ensure both
approaches yield the same result. This optimization is the most important
optimization in this program.
- Since:
- 1.8
- Version:
- 1.0 (February 18th, 2022)
- Author:
- Maysara Al Jumaily
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanareEqual(long v1, long v2)Returnstrueif both methods yield the same multiplication result of the two vectors specified,falseotherwise.voidbenchmarkOptimalMultiplication(long iterations)Generates 2x random vectors, where x is the iterations specified to test using the optimal solution the program uses.voidbenchmarkOptimalMultiplication(long iterations, long v1, long v2)Tests the multiplication of the two specified vectors x times, where x is the iterations specified.voidbenchmarkSlowMultiplication(long iterations)Generates 2x random vectors, where x is the iterations specified to test using the naive/slow solution.voidbenchmarkSlowMultiplication(long iterations, long v1, long v2)Tests the multiplication of the two specified vectors x times, where x is the iterations specified.voidinitComparison(long iterations)Multiplies two randomly generated row vectors x time, where x is the iterations specified to ensure both optimal and slow solutions yield the same output.booleanReturnstrueif the test was successful in the sense that both implementations yielded the same results,falseotherwise.
-
Constructor Details
-
QuaternaryVectorMultiplicationTester
public QuaternaryVectorMultiplicationTester(byte n)Initializes the test.- Parameters:
n- the length of the vectors to be tested.
-
-
Method Details
-
benchmarkOptimalMultiplication
public void benchmarkOptimalMultiplication(long iterations)Generates 2x random vectors, where x is the iterations specified to test using the optimal solution the program uses. Note that generating a randomlongwill take time because of randomness, not necessarily the time of the approach.- Parameters:
iterations- the number of random of times to test the multiplication of two random row vectors
-
benchmarkOptimalMultiplication
public void benchmarkOptimalMultiplication(long iterations, long v1, long v2)Tests the multiplication of the two specified vectors x times, where x is the iterations specified. It uses the optimal approach. Since the vector is specified, there is no randomness used, hence, the time will be more accurate.- Parameters:
iterations- the number of random of times to test the multiplication of two random row vectorsv1- the first vector to multiplyv2- the second vector to multiply
-
benchmarkSlowMultiplication
public void benchmarkSlowMultiplication(long iterations)Generates 2x random vectors, where x is the iterations specified to test using the naive/slow solution. Note that generating a randomlongwill take time because of randomness, not necessarily the time of the approach.- Parameters:
iterations- the number of random of times to test the multiplication of two random row vectors
-
benchmarkSlowMultiplication
public void benchmarkSlowMultiplication(long iterations, long v1, long v2)Tests the multiplication of the two specified vectors x times, where x is the iterations specified. It uses the slow/naive approach. Since the vector is specified, there is no randomness used, hence, the time will be more accurate.- Parameters:
iterations- the number of random of times to test the multiplication of two random row vectorsv1- the first vector to multiplyv2- the second vector to multiply
-
initComparison
public void initComparison(long iterations)Multiplies two randomly generated row vectors x time, where x is the iterations specified to ensure both optimal and slow solutions yield the same output. In the case where the result is not consist between the two methods, then the two vectors and two unequal solutions will be printed on screen. This is benchmarked but the amount of time doesn't have any significance.- Parameters:
iterations- the number of times to perform the multiplication of two randomly generated row vectors
-
areEqual
public boolean areEqual(long v1, long v2)Returnstrueif both methods yield the same multiplication result of the two vectors specified,falseotherwise.- Parameters:
v1- the first vector to multiplyv2- the second vector to multiply- Returns:
trueif both methods return the same result of multiplying the two specified vector,falseotherwise
-
isValidImplementation
public boolean isValidImplementation()Returnstrueif the test was successful in the sense that both implementations yielded the same results,falseotherwise.- Returns:
trueif the test was successful in the sense that both implementations yielded the same results,falseotherwise
-