Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiply, divide on Unit does not return same Unit #352

Open
samodadela opened this issue May 11, 2021 · 3 comments
Open

multiply, divide on Unit does not return same Unit #352

samodadela opened this issue May 11, 2021 · 3 comments
Labels

Comments

@samodadela
Copy link

Is this behavior correct?

Unit<Speed> u = METRE_PER_SECOND;
u.mulitply(0.001).divide(0.001) != u?

Test...

    private static final JsonMapper UOM_JSON_MAPPER = JsonMapper.builder()
                                                                .addModule(new UnitJacksonModule())
                                                                .build();

    public static String serialize(Object objectToSerialize) throws JsonProcessingException {

        return UOM_JSON_MAPPER.writeValueAsString(objectToSerialize);
    }

    @Test
    void mulTest() throws JsonProcessingException {
        Unit<Speed> one = METRE_PER_SECOND;
        System.out.println(serialize((one)));
        Unit<Speed> mul = one.multiply(0.001);
        System.out.println(serialize((mul)));
        Unit<Speed> div = mul.divide(0.001);
        System.out.println(serialize((div)));
    }

Output is:

"m/s"
"(m/s).0"
"((m/s).0).1000"

I'd expect to get back m/s. Also what does (m/s).0 mean?

@keilw
Copy link
Member

keilw commented May 11, 2021

I assume you're using Indriya, the RI, which version?
Because the API does not do these actual operations, I may transfer the issue into https://github.com/unitsofmeasurement/indriya but please could you tell us the exact implementation version and if any other libraries (e.g. uom-jackson or something older) did you get UnitJacksonModule from? Also the versions of those libraries would be good.

@samodadela
Copy link
Author

Yes, I'm using Indiriya. Does this help?

        <!-- Unit of Measurement -->
        <indriya.version>2.0.4</indriya.version>  <!-- required by uom-lib-jackson 2.0.1 (06.05.2021) -->
        <si-units.version>2.0.1</si-units.version>
        <uom-lib.version>2.0.1</uom-lib.version> <!-- 2.1 is latest, but uom-lib-jackson is only 2.0.1 (06.05.2021) -->
        <uom-systems.version>2.0.2</uom-systems.version>
        <uom-domain.version>2.0</uom-domain.version>
        
         ...


            <!-- Unit of Measurement https://github.com/unitsofmeasurement -->
            <!-- uom RI -->
            <dependency>
                <groupId>tech.units</groupId>
                <artifactId>indriya</artifactId>
                <version>${indriya.version}</version>
            </dependency>

            <!-- si-units -->
            <dependency>
                <groupId>si.uom</groupId>
                <artifactId>si-units</artifactId>
                <version>${si-units.version}</version>
            </dependency>

            <dependency>
                <groupId>si.uom</groupId>
                <artifactId>si-quantity</artifactId>
                <version>${si-units.version}</version>
            </dependency>

            <dependency>
                <groupId>tech.uom.lib</groupId>
                <artifactId>uom-lib-common</artifactId>
                <version>${uom-lib.version}</version>
            </dependency>

            <dependency>
                <groupId>tech.uom.lib</groupId>
                <artifactId>uom-lib-jackson</artifactId>
                <version>${uom-lib.version}</version>
            </dependency>

            <dependency>
                <groupId>tech.uom.lib</groupId>
                <artifactId>uom-lib-assertj</artifactId>
                <version>${uom-lib.version}</version>
                <scope>test</scope>
            </dependency>

            <!-- uom-systems -->
            <dependency>
                <groupId>systems.uom</groupId>
                <artifactId>systems-quantity</artifactId>
                <version>${uom-systems.version}</version>
            </dependency>

            <dependency>
                <groupId>systems.uom</groupId>
                <artifactId>systems-common</artifactId>
                <version>${uom-systems.version}</version>
            </dependency>

            <dependency>
                <groupId>systems.uom</groupId>
                <artifactId>systems-unicode</artifactId>
                <version>${uom-systems.version}</version>
            </dependency>

            <dependency>
                <groupId>systems.uom</groupId>
                <artifactId>systems-ucum</artifactId>
                <version>${uom-systems.version}</version>
            </dependency>

            <!-- uom-domain -->
            <dependency>
                <groupId>tech.uom.domain</groupId>
                <artifactId>uom-energy-quantity</artifactId>
                <version>${uom-domain.version}</version>
            </dependency>

            <dependency>
                <groupId>tech.uom.domain</groupId>
                <artifactId>uom-health-api</artifactId>
                <version>${uom-domain.version}</version>
            </dependency>

            <dependency>
                <groupId>tech.uom.domain</groupId>
                <artifactId>uom-health</artifactId>
                <version>${uom-domain.version}</version>
            </dependency>

            <dependency>
                <groupId>tech.uom.domain</groupId>
                <artifactId>uom-imaging</artifactId>
                <version>${uom-domain.version}</version>
            </dependency>

At first I wanted to report under Indriya but then I saw Unit is defined in unit-api.

@keilw keilw transferred this issue from unitsofmeasurement/unit-api May 14, 2021
@keilw keilw added the analysis label May 14, 2021
@keilw
Copy link
Member

keilw commented Aug 19, 2022

@samodadela A related ticket uom-lib#68 has been closed, did this also resolve the one here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants