Skip to content

Commit

Permalink
Add simple test cases for JavaHappyPandas
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoud Hanafy committed May 20, 2016
1 parent a252514 commit b96afd5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static DataFrame jsonLoadFromRDD(SQLContext sqlContext, JavaRDD<String> i
*/
public static DataFrame happyPandasPercentage(DataFrame pandaInfo) {
DataFrame happyPercentage = pandaInfo.select(pandaInfo.col("place"),
pandaInfo.col("happyPandas").divide(pandaInfo.col("totalPandas")).as("percentHappy"));
(pandaInfo.col("happyPandas").divide(pandaInfo.col("totalPandas"))).as("percentHappy"));
return happyPercentage;
}

Expand Down Expand Up @@ -204,7 +204,7 @@ public static void joins(DataFrame df1, DataFrame df2) {
}

public static DataFrame selfJoin(DataFrame df) {
return df.as("a").join(df.as("b")).where(df.col("name").equalTo(df.col("name")));
return (df.as("a")).join(df.as("b")).where("a.name = b.name");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ class HappyPandasTest extends DataFrameSuiteBase {
//tag::approxEqualDataFrames[]

test("verify simple happy pandas Percentage") {
val expectedResult = List(Row(toronto, 0.5), Row(sandiego, 2/3.0), Row(virginia, 1/10.0))
val expectedDf = createDF(expectedResult, ("place", StringType),
val expectedList = List(Row(toronto, 0.5), Row(sandiego, 2/3.0), Row(virginia, 1/10.0))
val expectedDf = createDF(expectedList, ("place", StringType),
("percentHappy", DoubleType))

val inputDF = sqlContext.createDataFrame(pandaInfoList)
val result = HappyPandas.happyPandasPercentage(inputDF)
val resultDF = HappyPandas.happyPandasPercentage(inputDF)

assertDataFrameApproximateEquals(expectedDf, result, 1E-5)
assertDataFrameApproximateEquals(expectedDf, resultDF, 1E-5)
}
//end::approxEqualDataFrames[]

Expand Down

0 comments on commit b96afd5

Please sign in to comment.