folone / poi.scala

Excel meets scalaz

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bug in wbInstance.equal

rintcius opened this issue Β· comments

I think I spotted a bug in 'wbInstance.equal' which I tried to fix, but there is more to it since now it breaks monoid laws (as shown by running the test that was skipped since it takes a long time) https://github.com/rintcius/poi.scala/compare/folone:master...rintcius:workbook-equals?expand=1

Not sure why it's breaking the law though. Any idea?

I can see how Workbook is breaking monoid laws because the Cell is breaking them. Namely, the NumericCell is breaking them by containing a Double which is not a lawful monoid: scalaz/scalaz#334. Not sure why Cell tests pass.

The change looks good to me πŸ‘

I guess, the best way would be to alter NumericCell to contain BigDecimal, which is a lawful monoid, AFAIR.

Isn't there something else at play? I tried with this:

  implicit def arbCell: Arbitrary[Cell] = Arbitrary(for {
    index      ← positiveInt
    stringData ← Gen.alphaStr
    boolData   ← arbitrary[Boolean]
    //doubleData ← arbitrary[Double]
    res        ← Gen.oneOf(StringCell(index, stringData),
      BooleanCell(index, boolData)/*, NumericCell(index, doubleData)*/)
  } yield res)

and Workbook still breaks. (Also Cell, Row, Sheet all pass)

See here for why I don't think NumericCell is the cause: https://github.com/folone/poi.scala/blob/master/src/main/scala/info.folone/package.scala#L16 and why Cell is successful.

Right. No idea then...

I think I found the reason of the failure: it happens when a workbook is constructed with 2 sheets that have the same name.

See satisfy right identity and satisfy left identity test cases that I added here https://github.com/rintcius/poi.scala/compare/folone:master...rintcius:workbook-equals?expand=1#diff-70fdc3da8e19f198aa397fe80479fdc2R98

But not sure how to solve this. Any suggestion?

One way to solve could be to make Workbook having a map from sheet names to sheets (instead of a set of sheets), but happy to hear your thoughts .

Fixed in #39