### Question:
LibSvm { public static void write(Writer writer, int classification, double... values) { try { writer.write(Integer.toString(classification)); for (int i = 0; i < values.length; i++) { double value = values[i]; if (value != 0) { writer.write(' '); writer.write(Integer.toString(i + 1)); writer.write(':'); writer.write(Float.toString((float) value)); } } writer.write('\n'); } catch (IOException e) { throw new RuntimeException(e); } }  static void write(Writer writer, int classification, double... values);  }### Answer:
@Test public void testLibSvm() { StringWriter w = new StringWriter(); LibSvm.write(w, 1, 2.3); assertEquals("1 1:2.3\n", w.toString()); }
@Test public void testLibSvmOnlyZeroValues() { StringWriter w = new StringWriter(); LibSvm.write(w, 1, 0); assertEquals("1\n", w.toString()); }
@Test public void testLibSvmSomeZeros() { StringWriter w = new StringWriter(); LibSvm.write(w, 101, 0, 0, 2, 0, 3); assertEquals("101 3:2.0 5:3.0\n", w.toString()); }