Copilot commented on code in PR #5792:
URL: https://github.com/apache/texera/pull/5792#discussion_r3440711763


##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/aggregate/DistributedAggregationSpec.scala:
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.aggregate
+
+import org.apache.texera.amber.core.tuple.{Attribute, AttributeType, Schema, 
Tuple}
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+class DistributedAggregationSpec extends AnyFlatSpec with Matchers {
+
+  // Representative average aggregation: partial = (sum, count)
+  private val avg: DistributedAggregation[(Double, Long)] = 
DistributedAggregation(
+    init    = () => (0.0, 0L),
+    iterate = (p, t) => (p._1 + t.getField[Double]("value"), p._2 + 1L),
+    merge   = (a, b) => (a._1 + b._1, a._2 + b._2),
+    finalAgg = p => (p._1 / p._2).asInstanceOf[Object]
+  )

Review Comment:
   This spec is meant to pin `DistributedAggregation`’s 4-function 
constructor/apply parameter order, but `avg` is built using **named 
arguments**. If someone accidentally reorders the case class parameters, this 
test would still bind by name and could keep passing, defeating the purpose. 
Construct `DistributedAggregation` positionally (as production code does) so 
reordering causes a behavioral test failure.



##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/aggregate/DistributedAggregationSpec.scala:
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.aggregate
+
+import org.apache.texera.amber.core.tuple.{Attribute, AttributeType, Schema, 
Tuple}
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+class DistributedAggregationSpec extends AnyFlatSpec with Matchers {
+
+  // Representative average aggregation: partial = (sum, count)
+  private val avg: DistributedAggregation[(Double, Long)] = 
DistributedAggregation(
+    init    = () => (0.0, 0L),
+    iterate = (p, t) => (p._1 + t.getField[Double]("value"), p._2 + 1L),
+    merge   = (a, b) => (a._1 + b._1, a._2 + b._2),
+    finalAgg = p => (p._1 / p._2).asInstanceOf[Object]
+  )
+
+  private val schema: Schema =
+    Schema(List(new Attribute("value", AttributeType.DOUBLE)))
+
+  private def tuple(v: Double): Tuple = Tuple(schema, Array(v))
+
+  // -------------------------------------------------------------------------
+  // init
+  // -------------------------------------------------------------------------
+
+  "DistributedAggregation.init" should "return the identity partial (0.0, 0L)" 
in {
+    avg.init() shouldBe (0.0, 0L)
+  }
+
+  // -------------------------------------------------------------------------
+  // iterate
+  // -------------------------------------------------------------------------
+
+  "DistributedAggregation.iterate" should "accumulate sum and count from each 
tuple" in {
+    var p = avg.init()
+    p = avg.iterate(p, tuple(3.0))
+    p = avg.iterate(p, tuple(7.0))
+    p shouldBe (10.0, 2L)
+  }
+
+  it should "leave the partial unchanged when called on an empty sequence" in {
+    val p = avg.init()
+    // iterating zero times is the empty-partition case
+    p shouldBe avg.init()
+  }

Review Comment:
   This example-based test case doesn’t exercise `iterate` at all (it just 
compares `init()` to itself), so it can’t fail and is misleading. Consider 
removing it and simplifying the preceding test to use 
`foldLeft(avg.init())(avg.iterate)` to express the partition-fold contract 
directly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to