From 2b7a6d9e50dff597ef169f7c2d79c8998309f00b Mon Sep 17 00:00:00 2001 From: Xinyuan Lin Date: Tue, 30 Jun 2026 18:24:26 -0700 Subject: [PATCH 1/2] test(workflow-operator): add unit test coverage for ML scorer metric and sort enums --- .../Scorer/classificationMetricsFncSpec.scala | 43 +++++++++++++++++++ .../Scorer/regressionMetricsFncSpec.scala | 43 +++++++++++++++++++ .../operator/sort/SortPreferenceSpec.scala | 38 ++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/machineLearning/Scorer/classificationMetricsFncSpec.scala create mode 100644 common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/machineLearning/Scorer/regressionMetricsFncSpec.scala create mode 100644 common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sort/SortPreferenceSpec.scala 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..f5a800a2d82 --- /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..1e3c0a70630 --- /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 + } +} From 576a3d12ab686410b53c9956fd7c5a761705d74e Mon Sep 17 00:00:00 2001 From: Xinyuan Lin Date: Tue, 30 Jun 2026 18:55:44 -0700 Subject: [PATCH 2/2] test(workflow-operator): rename metric enum specs to UpperCamelCase Per review: rename classificationMetricsFncSpec/regressionMetricsFncSpec (class + file) to ClassificationMetricsFncSpec/RegressionMetricsFncSpec for Scala naming consistency and test-report discoverability. --- ...nMetricsFncSpec.scala => ClassificationMetricsFncSpec.scala} | 2 +- ...ssionMetricsFncSpec.scala => RegressionMetricsFncSpec.scala} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/machineLearning/Scorer/{classificationMetricsFncSpec.scala => ClassificationMetricsFncSpec.scala} (96%) rename common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/machineLearning/Scorer/{regressionMetricsFncSpec.scala => RegressionMetricsFncSpec.scala} (96%) 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 similarity index 96% rename from common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/machineLearning/Scorer/classificationMetricsFncSpec.scala rename to common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/machineLearning/Scorer/ClassificationMetricsFncSpec.scala index f5a800a2d82..5b1cbd1b87a 100644 --- 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 @@ -23,7 +23,7 @@ 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 { +class ClassificationMetricsFncSpec extends AnyFlatSpec with Matchers { "classificationMetricsFnc" should "map each constant to its wire value" in { classificationMetricsFnc.accuracy.getName shouldBe "Accuracy" 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 similarity index 96% rename from common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/machineLearning/Scorer/regressionMetricsFncSpec.scala rename to common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/machineLearning/Scorer/RegressionMetricsFncSpec.scala index 1e3c0a70630..6d822f46d6f 100644 --- 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 @@ -23,7 +23,7 @@ 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 { +class RegressionMetricsFncSpec extends AnyFlatSpec with Matchers { "regressionMetricsFnc" should "map each constant to its wire value" in { regressionMetricsFnc.mse.getName shouldBe "MSE"