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

Solving unit equivalence #59

Merged
merged 13 commits into from
Apr 22, 2018
Merged

Solving unit equivalence #59

merged 13 commits into from
Apr 22, 2018

Conversation

andi-huber
Copy link
Member

@andi-huber andi-huber commented Apr 20, 2018

Might be a requirement to solve the unit equivalence problem ...
unitsofmeasurement/unit-api#89


This change is Reviewable

@andi-huber
Copy link
Member Author

In the meantime I reworked the way identity transformations are handled when composing UnitConverters. Also this is a first step of solving:
#3

@andi-huber andi-huber changed the title 89: adds tests for converter composition Solving unit equivalence Apr 21, 2018
@andi-huber
Copy link
Member Author

With PrefixTest we have 2 disabled tests, testing for equality. We can show now that testing for equivalence does work:

  @Test
  public void testEquivalence() {
	  ComparableUnit a = (ComparableUnit) MICRO(GRAM); 
	  ComparableUnit b = (ComparableUnit) GRAM.divide(1_000_000);
	  assertEquals(true, a.isEquivalentOf(b));
  }

  @Test
  public void testNestedEquivalence() {
	  ComparableUnit a = (ComparableUnit) MICRO(GRAM);
	  ComparableUnit b = (ComparableUnit) GRAM.divide(1000).divide(1000);
	  assertEquals(true, a.isEquivalentOf(b));
  }

@andi-huber
Copy link
Member Author

TODO
Fix failing CompositionEquivalenceTest tests by completing

  • AbstractUnit.Simplifier TODOs
  • any concrete UnitConverters that do not yet fully implement AbstractConverter's

	/**
	 * Guard for {@link #simpleCompose(AbstractConverter)}
	 * @param that
	 * @return whether or not a 'simple' composition of transformations is possible
	 */
	protected abstract boolean isSimpleCompositionWith(AbstractConverter that);
	
	/**
	 * Guarded by {@link #isSimpleCompositionWith(AbstractConverter)}
	 * @param that
	 * @return a new AbstractConverter that adds no additional conversion step
	 */
	protected AbstractConverter simpleCompose(AbstractConverter that) {
		throw new IllegalStateException(
				String.format("Concrete UnitConverter '%s' does not implement simpleCompose(...).", this)); 
	}

@keilw keilw merged commit 5274b0a into unitsofmeasurement:master Apr 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants