Github user Lewuathe commented on a diff in the pull request: https://github.com/apache/spark/pull/8537#discussion_r38996940 --- Diff: mllib/src/test/java/org/apache/spark/ml/source/JavaLibSVMRelationSuite.java --- @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.ml.source; + +import java.io.File; +import java.io.IOException; + +import com.google.common.base.Charsets; +import com.google.common.io.Files; + +import org.apache.spark.mllib.linalg.DenseVector; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import org.apache.spark.api.java.JavaSparkContext; +import org.apache.spark.mllib.linalg.Vectors; +import org.apache.spark.sql.DataFrame; +import org.apache.spark.sql.Row; +import org.apache.spark.sql.SQLContext; +import org.apache.spark.util.Utils; + + +/** + * Test LibSVMRelation in Java. + */ +public class JavaLibSVMRelationSuite { + private transient JavaSparkContext jsc; + private transient SQLContext jsql; + private transient DataFrame dataset; + + private File path; + + @Before + public void setUp() throws IOException { + jsc = new JavaSparkContext("local", "JavaLibSVMRelationSuite"); + jsql = new SQLContext(jsc); + + File tmpDir = Utils.createTempDir(System.getProperty("java.io.tmpdir"), "datasource"); + path = File.createTempFile("datasource", "libsvm-relation", tmpDir); + + String s = "1 1:1.0 3:2.0 5:3.0\n0\n0 2:4.0 4:5.0 6:6.0"; + Files.write(s, path, Charsets.US_ASCII); + } + + @After + public void tearDown() { + jsc.stop(); + jsc = null; + path.delete(); + } + + @Test + public void verifyLibSVMDF() { + dataset = jsql.read().format("libsvm").option("vectorType", "dense").load(path.getPath()); + Assert.assertEquals("label", dataset.columns()[0]); + Assert.assertEquals("features", dataset.columns()[1]); + Row r = dataset.first(); + Assert.assertEquals(Double.valueOf(1.0), Double.valueOf(r.getDouble(0))); --- End diff -- Yes, I tried. `assertEquals` does not seem to be able to compare primitive floating-point numbers. ``` java.lang.AssertionError: Use assertEquals(expected, actual, delta) to compare floating-point numbers at org.junit.Assert.fail(Assert.java:93) at org.junit.Assert.assertEquals(Assert.java:493) at org.junit.Assert.assertEquals(Assert.java:482) at org.apache.spark.ml.source.JavaLibSVMRelationSuite.verifyLibSVMDF(JavaLibSVMRelationSuite.java:75) ```
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org