-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
306 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js'; | ||
|
||
import { M } from '@endo/patterns'; | ||
import { AmountMath as am } from '../../src/index.js'; | ||
import { mockNatBrand } from './mathHelpers/mockBrand.js'; | ||
|
||
// Each of the test results marked "conservative" below are allowed to get | ||
// more accurate over time. They may not become less accurate. | ||
// Once a test result is marked "accurate", it must not change. | ||
|
||
test('frugalSplit', t => { | ||
const $ = value => | ||
harden({ | ||
brand: mockNatBrand, | ||
value, | ||
}); | ||
|
||
// ground patterns, i.e., which patterns which are concrete amounts | ||
t.deepEqual(am.frugalSplit($(3n), $(2n)), { | ||
// accurate | ||
matched: $(2n), | ||
change: $(1n), | ||
}); | ||
|
||
// outer amount patterns | ||
t.deepEqual(am.frugalSplit($(3n), M.any()), { | ||
// accurate | ||
matched: $(0n), | ||
change: $(3n), | ||
}); | ||
t.deepEqual(am.frugalSplit($(3n), M.gte($(2n))), { | ||
// conservative | ||
matched: $(3n), | ||
change: $(0n), | ||
}); | ||
t.deepEqual(am.frugalSplit($(3n), M.lte($(2n))), { | ||
// accurate | ||
matched: $(0n), | ||
change: $(3n), | ||
}); | ||
t.deepEqual( | ||
am.frugalSplit($(3n), M.and($(2n))), | ||
// conservative | ||
undefined, | ||
); | ||
t.deepEqual(am.frugalSplit($(3n), M.and($(0n))), { | ||
// accurate | ||
matched: $(0n), | ||
change: $(3n), | ||
}); | ||
t.deepEqual(am.frugalSplit($(3n), M.and($(3n))), { | ||
// accurate | ||
matched: $(3n), | ||
change: $(0n), | ||
}); | ||
|
||
// inner amount patterns, i.e., amount-value patterns | ||
t.deepEqual(am.frugalSplit($(3n), $(M.any())), { | ||
// accurate | ||
matched: $(0n), | ||
change: $(3n), | ||
}); | ||
t.deepEqual(am.frugalSplit($(3n), $(M.gte(2n))), { | ||
// conservative | ||
matched: $(3n), | ||
change: $(0n), | ||
}); | ||
t.deepEqual(am.frugalSplit($(3n), $(M.lte(2n))), { | ||
// accurate | ||
matched: $(0n), | ||
change: $(3n), | ||
}); | ||
t.deepEqual( | ||
am.frugalSplit($(3n), $(M.and(2n))), | ||
// conservative | ||
undefined, | ||
); | ||
t.deepEqual(am.frugalSplit($(3n), $(M.and(0n))), { | ||
// accurate | ||
matched: $(0n), | ||
change: $(3n), | ||
}); | ||
t.deepEqual(am.frugalSplit($(3n), $(M.and(3n))), { | ||
// accurate | ||
matched: $(3n), | ||
change: $(0n), | ||
}); | ||
}); |
Oops, something went wrong.