Class QuaternaryVectorMultiplicationTester

java.lang.Object
hlcd.testing.optimizationTester.QuaternaryVectorMultiplicationTester

public class QuaternaryVectorMultiplicationTester extends Object
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
    Constructor
    Description
    Initializes the test.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    areEqual​(long v1, long v2)
    Returns true if both methods yield the same multiplication result of the two vectors specified, false otherwise.
    void
    benchmarkOptimalMultiplication​(long iterations)
    Generates 2x random vectors, where x is the iterations specified to test using the optimal solution the program uses.
    void
    benchmarkOptimalMultiplication​(long iterations, long v1, long v2)
    Tests the multiplication of the two specified vectors x times, where x is the iterations specified.
    void
    benchmarkSlowMultiplication​(long iterations)
    Generates 2x random vectors, where x is the iterations specified to test using the naive/slow solution.
    void
    benchmarkSlowMultiplication​(long iterations, long v1, long v2)
    Tests the multiplication of the two specified vectors x times, where x is the iterations specified.
    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.
    boolean
    Returns true if the test was successful in the sense that both implementations yielded the same results, false otherwise.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 random long will 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 vectors
      v1 - the first vector to multiply
      v2 - 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 random long will 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 vectors
      v1 - the first vector to multiply
      v2 - 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)
      Returns true if both methods yield the same multiplication result of the two vectors specified, false otherwise.
      Parameters:
      v1 - the first vector to multiply
      v2 - the second vector to multiply
      Returns:
      true if both methods return the same result of multiplying the two specified vector, false otherwise
    • isValidImplementation

      public boolean isValidImplementation()
      Returns true if the test was successful in the sense that both implementations yielded the same results, false otherwise.
      Returns:
      true if the test was successful in the sense that both implementations yielded the same results, false otherwise