diff --git a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/machineLearning/Scorer/ClassificationMetricsFncSpec.scala b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/machineLearning/Scorer/ClassificationMetricsFncSpec.scala new file mode 100644 index 00000000000..5b1cbd1b87a --- /dev/null +++ b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/machineLearning/Scorer/ClassificationMetricsFncSpec.scala @@ -0,0 +1,43 @@ +/* + * 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.texera.amber.operator.machineLearning.Scorer + +import org.apache.texera.amber.util.JSONUtils.objectMapper +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +class ClassificationMetricsFncSpec extends AnyFlatSpec with Matchers { + + "classificationMetricsFnc" should "map each constant to its wire value" in { + classificationMetricsFnc.accuracy.getName shouldBe "Accuracy" + classificationMetricsFnc.precisionScore.getName shouldBe "Precision Score" + classificationMetricsFnc.recallScore.getName shouldBe "Recall Score" + classificationMetricsFnc.f1Score.getName shouldBe "F1 Score" + classificationMetricsFnc.values() should have length 4 + } + + "classificationMetricsFnc" should "round-trip through Jackson using its wire value" in { + objectMapper.writeValueAsString(classificationMetricsFnc.f1Score) shouldBe "\"F1 Score\"" + objectMapper.readValue( + "\"F1 Score\"", + classOf[classificationMetricsFnc] + ) shouldBe classificationMetricsFnc.f1Score + } +} diff --git a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/machineLearning/Scorer/RegressionMetricsFncSpec.scala b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/machineLearning/Scorer/RegressionMetricsFncSpec.scala new file mode 100644 index 00000000000..6d822f46d6f --- /dev/null +++ b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/machineLearning/Scorer/RegressionMetricsFncSpec.scala @@ -0,0 +1,43 @@ +/* + * 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.texera.amber.operator.machineLearning.Scorer + +import org.apache.texera.amber.util.JSONUtils.objectMapper +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +class RegressionMetricsFncSpec extends AnyFlatSpec with Matchers { + + "regressionMetricsFnc" should "map each constant to its wire value" in { + regressionMetricsFnc.mse.getName shouldBe "MSE" + regressionMetricsFnc.rmse.getName shouldBe "RMSE" + regressionMetricsFnc.mae.getName shouldBe "MAE" + regressionMetricsFnc.r2.getName shouldBe "R2" + regressionMetricsFnc.values() should have length 4 + } + + "regressionMetricsFnc" should "round-trip through Jackson using its wire value" in { + objectMapper.writeValueAsString(regressionMetricsFnc.rmse) shouldBe "\"RMSE\"" + objectMapper.readValue( + "\"RMSE\"", + classOf[regressionMetricsFnc] + ) shouldBe regressionMetricsFnc.rmse + } +} diff --git a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sort/SortPreferenceSpec.scala b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sort/SortPreferenceSpec.scala new file mode 100644 index 00000000000..53c78ab8e76 --- /dev/null +++ b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sort/SortPreferenceSpec.scala @@ -0,0 +1,38 @@ +/* + * 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.texera.amber.operator.sort + +import org.apache.texera.amber.util.JSONUtils.objectMapper +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +class SortPreferenceSpec extends AnyFlatSpec with Matchers { + + "SortPreference" should "expose exactly the ascending and descending constants" in { + SortPreference.values() should have length 2 + SortPreference.valueOf("ASC") shouldBe SortPreference.ASC + SortPreference.valueOf("DESC") shouldBe SortPreference.DESC + } + + "SortPreference" should "round-trip through Jackson using its constant name" in { + objectMapper.writeValueAsString(SortPreference.ASC) shouldBe "\"ASC\"" + objectMapper.readValue("\"DESC\"", classOf[SortPreference]) shouldBe SortPreference.DESC + } +}