### Question:
LinearSystemSolver { public static Solver getSolver(double[] packed) { if (packed == null) { return null; } int dim = (int) Math.round((Math.sqrt(8.0 * packed.length + 1.0) - 1.0) / 2.0); double[][] unpacked = new double[dim][dim]; int offset = 0; for (int col = 0; col < dim; col++) { double[] unpackedCol = unpacked[col]; for (int row = col; row < dim; row++) { unpacked[row][col] = unpackedCol[row] = packed[offset++]; } } return getSolver(unpacked); } private  LinearSystemSolver(); static Solver getSolver(double[] packed);  }### Answer:
@Test public void testNull() { assertNull(LinearSystemSolver.getSolver((double[]) null)); assertNull(LinearSystemSolver.getSolver((double[][]) null)); }
@Test public void testSolveFToF() { double[][] a = { {1.3, -2.0, 3.0}, {2.0, 0.0, 5.0}, {0.0, -1.5, 5.5}, }; Solver solver = LinearSystemSolver.getSolver(a); assertNotNull(solver); float[] y = solver.solveFToF(new float[] {1.0f, 2.0f, 6.5f}); assertArrayEquals(new float[] {-1.956044f, 0.0021978023f, 1.1824176f}, y); }
@Test public void testSolveDToD() { double[][] a = { {1.3, -2.0, 3.0}, {2.0, 0.0, 5.0}, {0.0, -1.5, 5.5}, }; Solver solver = LinearSystemSolver.getSolver(a); assertNotNull(solver); double[] y = solver.solveDToD(new double[] {1.0, 2.0, 6.5}); assertArrayEquals( new double[] {-1.9560439560439564, 0.002197802197802894, 1.1824175824175824}, y); }
@Test public void testSolveDToDPacked() { double[] a = {1.3, -2.0, 2.0, 3.0, 5.0, 1.5}; Solver solver = LinearSystemSolver.getSolver(a); assertNotNull(solver); double[] y = solver.solveDToD(new double[] {1.0, 2.0, 6.5}); assertArrayEquals( new double[] {1.163614884819846, 0.701122268163024, 0.444772593030124}, y); }
@Test public void testApparentRank() { try { LinearSystemSolver.getSolver(new double[][] { {1.3001, -2.0, 3.0}, {2.6, -4.0001, 6.0001}, {0.0, -1.5, 5.5}, }); fail("Expected singular matrix"); } catch (SingularMatrixSolverException smse) { assertEquals(2, smse.getApparentRank()); } try { LinearSystemSolver.getSolver(new double[][] { {1.3001, -2.0, 3.0}, {2.6, -4.0001, 6.0001}, {1.3, -2.0002, 3.0002}, }); fail("Expected singular matrix"); } catch (SingularMatrixSolverException smse) { assertEquals(1, smse.getApparentRank()); } }