SpartanRefactoring / Main

Eclipse plugin that performs automatic refactoring of Java source code, making it shorter, more idiomatic and more readable
https://www.spartan.org.il
100 stars 56 forks source link

The spartianizer changed my code and caused tests to fail #1618

Open noamyft opened 7 years ago

noamyft commented 7 years ago

I just spartinzed my class. After I run the test, I discovered 2 tests failed. When I looked into it, I discover that the spartanizer change my code: Form this:

        return storePackages.stream().map(sp -> {
            long periodInDays = ChronoUnit.DAYS.between(currentDate, sp.getExpirationDate());
            double ratio = periodInDays == 0 ? 0 : sp.getAmount() / periodInDays;
            return new HighRatioAmountExpirationTimeProperty(ratio, sp);
        }).filter(p -> p.getRatio() >= HighRatioAmountExpirationTimeProperty.ratioThreshold)
                .collect(Collectors.toSet());

To this:


        return storePackages.stream().map(sp -> {
            long periodInDays = ChronoUnit.DAYS.between(currentDate, sp.getExpirationDate());
            double ratio = periodInDays == 0 ? 0 : periodInDays * sp.getAmount() / 1.;
            return new HighRatioAmountExpirationTimeProperty(ratio, sp);
        }).filter(p -> p.getRatio() >= HighRatioAmountExpirationTimeProperty.ratioThreshold)
                .collect(Collectors.toSet());

Meaning, this: sp.getAmount() / periodInDays changed to this: *periodInDays sp.getAmount() / 1.**

From what I understand, it changed the operation from division to multiplication. If so, this is seriously bad.

OriRoth commented 7 years ago

@ravivos why did you assigned me? I am not related to arithmetic tippers. Talk to Yossi/Niv please.