Skip to content

Commit 6c48d8d

Browse files
authored
Merge pull request #41 from danoliv/OneMultiplicationBug
Fix multiplication bug on One object
2 parents e65a592 + 6e4da89 commit 6c48d8d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

core/src/main/scala/optimus/algebra/Expression.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* \///// \/// \///// \/// \/// \/// \/// \///////// \//////////
1212
*
1313
* The mathematical programming library for Scala.
14-
*
14+
*
1515
*/
1616

1717
package optimus.algebra
@@ -235,7 +235,7 @@ case object Zero extends Const(0) {
235235

236236
case object One extends Const(1) {
237237

238-
override def *(expression: Expression): Expression = this
238+
override def *(expression: Expression): Expression = expression
239239

240240
override def unary_- : Const = Const(-1)
241241
}

core/src/test/scala/optimus/algebra/AlgebraSpecTest.scala

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* \///// \/// \///// \/// \/// \/// \/// \///////// \//////////
1212
*
1313
* The mathematical programming library for Scala.
14-
*
14+
*
1515
*/
1616

1717
package optimus.algebra
@@ -326,4 +326,12 @@ final class AlgebraSpecTest extends AnyFunSpec with Matchers {
326326
constraint_1.equals(constraint_2) shouldEqual false
327327
}
328328
}
329+
330+
describe("Limit cases") {
331+
def multiply(ex: Expression, d: Double): Expression = ex * d
332+
333+
it("1 * c should be equal to c (and not to 1)") {
334+
multiply(One, 10.0) shouldBe Const(10.0)
335+
}
336+
}
329337
}

0 commit comments

Comments
 (0)