|
@@ -7,6 +7,7 @@
|
|
|
import { OrderedSet } from 'mol-data/int'
|
|
|
import AtomSet from '../structure/atom/set'
|
|
|
import Atom from '../structure/atom'
|
|
|
+import AtomGroup from '../structure/atom/group'
|
|
|
|
|
|
describe('atom set', () => {
|
|
|
const p = (i: number, j: number) => Atom.create(i, j);
|
|
@@ -21,7 +22,7 @@ describe('atom set', () => {
|
|
|
}
|
|
|
|
|
|
it('singleton pair', () => {
|
|
|
- const set = AtomSet.create(p(10, 11));
|
|
|
+ const set = AtomSet.ofAtoms([p(10, 11)], AtomSet.Empty);
|
|
|
expect(setToPairs(set)).toEqual([p(10, 11)]);
|
|
|
expect(AtomSet.atomHas(set, p(10, 11))).toBe(true);
|
|
|
expect(AtomSet.atomHas(set, p(11, 11))).toBe(false);
|
|
@@ -29,16 +30,20 @@ describe('atom set', () => {
|
|
|
expect(AtomSet.atomCount(set)).toBe(1);
|
|
|
});
|
|
|
|
|
|
- it('singleton number', () => {
|
|
|
- const set = AtomSet.create(p(10, 11));
|
|
|
+ it('singleton atom', () => {
|
|
|
+ const set = AtomSet.singleton(p(10, 11), AtomSet.Empty);
|
|
|
expect(setToPairs(set)).toEqual([p(10, 11)]);
|
|
|
+ expect(AtomSet.atomHas(set, p(10, 11))).toBe(true);
|
|
|
+ expect(AtomSet.atomHas(set, p(11, 11))).toBe(false);
|
|
|
+ expect(AtomSet.atomGetAt(set, 0)).toBe(p(10, 11));
|
|
|
+ expect(AtomSet.atomCount(set)).toBe(1);
|
|
|
});
|
|
|
|
|
|
it('multi', () => {
|
|
|
- const set = AtomSet.create({
|
|
|
- 1: OrderedSet.ofSortedArray([4, 6, 7]),
|
|
|
- 3: OrderedSet.ofRange(0, 1),
|
|
|
- });
|
|
|
+ const gen = AtomSet.Generator();
|
|
|
+ gen.add(1, AtomGroup.createNew(OrderedSet.ofSortedArray([4, 6, 7])));
|
|
|
+ gen.add(3, AtomGroup.createNew(OrderedSet.ofRange(0, 1)));
|
|
|
+ const set = gen.getSet();
|
|
|
const ret = [p(1, 4), p(1, 6), p(1, 7), p(3, 0), p(3, 1)];
|
|
|
expect(AtomSet.atomCount(set)).toBe(ret.length);
|
|
|
expect(setToPairs(set)).toEqual([p(1, 4), p(1, 6), p(1, 7), p(3, 0), p(3, 1)]);
|
|
@@ -50,18 +55,58 @@ describe('atom set', () => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ it('template', () => {
|
|
|
+ const template = AtomSet.ofAtoms([p(1, 3), p(0, 1), p(0, 6), p(0, 2)], AtomSet.Empty)
|
|
|
+ const gen = AtomSet.TemplateGenerator(template);
|
|
|
+ gen.add(0, OrderedSet.ofSortedArray([1, 2, 6]));
|
|
|
+ gen.add(1, OrderedSet.ofSingleton(3));
|
|
|
+ const set = gen.getSet();
|
|
|
+
|
|
|
+ expect(AtomSet.unitGetById(set, 0)).toBe(AtomSet.unitGetById(template, 0));
|
|
|
+ expect(AtomSet.unitGetById(set, 1)).toBe(AtomSet.unitGetById(template, 1));
|
|
|
+ expect(set).toBe(template);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('template 1', () => {
|
|
|
+ const template = AtomSet.ofAtoms([p(1, 3), p(0, 1), p(0, 6), p(0, 2)], AtomSet.Empty)
|
|
|
+ const gen = AtomSet.TemplateGenerator(template);
|
|
|
+ gen.add(0, OrderedSet.ofSortedArray([1, 2, 6]));
|
|
|
+ gen.add(1, OrderedSet.ofSingleton(4));
|
|
|
+ const set = gen.getSet();
|
|
|
+
|
|
|
+ expect(AtomSet.unitGetById(set, 0)).toBe(AtomSet.unitGetById(template, 0));
|
|
|
+ expect(AtomSet.unitGetById(set, 1) === AtomSet.unitGetById(template, 1)).toBe(false);
|
|
|
+ expect(set === template).toBe(false);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('template union', () => {
|
|
|
+ const template = AtomSet.ofAtoms([p(1, 3), p(0, 1), p(0, 6), p(0, 2)], AtomSet.Empty)
|
|
|
+
|
|
|
+ const p13 = AtomSet.ofAtoms([p(1, 3)], AtomSet.Empty);
|
|
|
+ const p01 = AtomSet.ofAtoms([p(0, 1)], AtomSet.Empty);
|
|
|
+ const p02 = AtomSet.ofAtoms([p(0, 2)], AtomSet.Empty);
|
|
|
+ const p06 = AtomSet.ofAtoms([p(0, 6)], AtomSet.Empty);
|
|
|
+
|
|
|
+ const u0 = AtomSet.union([p01, p02, p06], template);
|
|
|
+ const u1 = AtomSet.union([p01, p02, p06, p13], template);
|
|
|
+ expect(AtomSet.unitGetById(u0, 0)).toBe(AtomSet.unitGetById(template, 0));
|
|
|
+ expect(AtomSet.unitGetById(u1, 0)).toBe(AtomSet.unitGetById(template, 0));
|
|
|
+ expect(AtomSet.unitGetById(u1, 1)).toBe(AtomSet.unitGetById(template, 1));
|
|
|
+ expect(u1).toBe(template);
|
|
|
+ });
|
|
|
+
|
|
|
it('element at / index of', () => {
|
|
|
const control: Atom[] = [];
|
|
|
- const sets = Object.create(null);
|
|
|
+ const gen = AtomSet.Generator();
|
|
|
for (let i = 1; i < 10; i++) {
|
|
|
const set = [];
|
|
|
for (let j = 1; j < 7; j++) {
|
|
|
control[control.length] = p(i * i, j * j + 1);
|
|
|
set[set.length] = j * j + 1;
|
|
|
}
|
|
|
- sets[i * i] = OrderedSet.ofSortedArray(set);
|
|
|
+ gen.add(i * i, AtomGroup.createNew(OrderedSet.ofSortedArray(set)));
|
|
|
}
|
|
|
- const ms = AtomSet.create(sets);
|
|
|
+ const ms = gen.getSet();
|
|
|
for (let i = 0; i < control.length; i++) {
|
|
|
expect(Atom.areEqual(AtomSet.atomGetAt(ms, i), control[i])).toBe(true);
|
|
|
}
|
|
@@ -72,17 +117,17 @@ describe('atom set', () => {
|
|
|
});
|
|
|
|
|
|
it('packed pairs', () => {
|
|
|
- const set = AtomSet.create([p(1, 3), p(0, 1), p(0, 6), p(0, 2)]);
|
|
|
+ const set = AtomSet.ofAtoms([p(1, 3), p(0, 1), p(0, 6), p(0, 2)], AtomSet.Empty);
|
|
|
expect(setToPairs(set)).toEqual([p(0, 1), p(0, 2), p(0, 6), p(1, 3)]);
|
|
|
});
|
|
|
|
|
|
it('equality', () => {
|
|
|
- const a = AtomSet.create([p(1, 3), p(0, 1), p(0, 6), p(0, 2)]);
|
|
|
- const b = AtomSet.create([p(1, 3), p(0, 1), p(0, 6), p(0, 2)]);
|
|
|
- const c = AtomSet.create([p(1, 3), p(0, 4), p(0, 6), p(0, 2)]);
|
|
|
- const d = AtomSet.create([p(1, 3)]);
|
|
|
- const e = AtomSet.create([p(1, 3)]);
|
|
|
- const f = AtomSet.create([p(3, 3)]);
|
|
|
+ const a = AtomSet.ofAtoms([p(1, 3), p(0, 1), p(0, 6), p(0, 2)], AtomSet.Empty);
|
|
|
+ const b = AtomSet.ofAtoms([p(1, 3), p(0, 1), p(0, 6), p(0, 2)], AtomSet.Empty);
|
|
|
+ const c = AtomSet.ofAtoms([p(1, 3), p(0, 4), p(0, 6), p(0, 2)], AtomSet.Empty);
|
|
|
+ const d = AtomSet.ofAtoms([p(1, 3)], AtomSet.Empty);
|
|
|
+ const e = AtomSet.ofAtoms([p(1, 3)], AtomSet.Empty);
|
|
|
+ const f = AtomSet.ofAtoms([p(3, 3)], AtomSet.Empty);
|
|
|
|
|
|
expect(AtomSet.areEqual(a, a)).toBe(true);
|
|
|
expect(AtomSet.areEqual(a, b)).toBe(true);
|
|
@@ -94,13 +139,13 @@ describe('atom set', () => {
|
|
|
});
|
|
|
|
|
|
it('are intersecting', () => {
|
|
|
- const a = AtomSet.create([p(1, 3), p(0, 1), p(0, 6), p(0, 2)]);
|
|
|
- const b = AtomSet.create([p(1, 3), p(0, 1), p(0, 6), p(0, 2)]);
|
|
|
- const c = AtomSet.create([p(1, 3), p(0, 4), p(0, 6), p(0, 2)]);
|
|
|
- const d = AtomSet.create([p(1, 3)]);
|
|
|
- const e = AtomSet.create([p(1, 3)]);
|
|
|
- const f = AtomSet.create([p(3, 3)]);
|
|
|
- const g = AtomSet.create([p(10, 3), p(8, 1), p(7, 6), p(3, 2)]);
|
|
|
+ const a = AtomSet.ofAtoms([p(1, 3), p(0, 1), p(0, 6), p(0, 2)], AtomSet.Empty);
|
|
|
+ const b = AtomSet.ofAtoms([p(1, 3), p(0, 1), p(0, 6), p(0, 2)], AtomSet.Empty);
|
|
|
+ const c = AtomSet.ofAtoms([p(1, 3), p(0, 4), p(0, 6), p(0, 2)], AtomSet.Empty);
|
|
|
+ const d = AtomSet.ofAtoms([p(1, 3)], AtomSet.Empty);
|
|
|
+ const e = AtomSet.ofAtoms([p(1, 3)], AtomSet.Empty);
|
|
|
+ const f = AtomSet.ofAtoms([p(3, 3)], AtomSet.Empty);
|
|
|
+ const g = AtomSet.ofAtoms([p(10, 3), p(8, 1), p(7, 6), p(3, 2)], AtomSet.Empty);
|
|
|
|
|
|
expect(AtomSet.areIntersecting(a, a)).toBe(true);
|
|
|
expect(AtomSet.areIntersecting(a, b)).toBe(true);
|
|
@@ -113,10 +158,10 @@ describe('atom set', () => {
|
|
|
});
|
|
|
|
|
|
it('intersection', () => {
|
|
|
- const a = AtomSet.create([p(1, 3), p(0, 1), p(0, 6), p(0, 2)]);
|
|
|
- const b = AtomSet.create([p(10, 3), p(0, 1), p(0, 6), p(4, 2)]);
|
|
|
- const c = AtomSet.create([p(1, 3)]);
|
|
|
- const d = AtomSet.create([p(2, 3)]);
|
|
|
+ const a = AtomSet.ofAtoms([p(1, 3), p(0, 1), p(0, 6), p(0, 2)], AtomSet.Empty);
|
|
|
+ const b = AtomSet.ofAtoms([p(10, 3), p(0, 1), p(0, 6), p(4, 2)], AtomSet.Empty);
|
|
|
+ const c = AtomSet.ofAtoms([p(1, 3)], AtomSet.Empty);
|
|
|
+ const d = AtomSet.ofAtoms([p(2, 3)], AtomSet.Empty);
|
|
|
expect(AtomSet.intersect(a, a)).toBe(a);
|
|
|
expect(setToPairs(AtomSet.intersect(a, b))).toEqual([p(0, 1), p(0, 6)]);
|
|
|
expect(setToPairs(AtomSet.intersect(a, c))).toEqual([p(1, 3)]);
|
|
@@ -124,12 +169,12 @@ describe('atom set', () => {
|
|
|
});
|
|
|
|
|
|
it('subtract', () => {
|
|
|
- const a = AtomSet.create([p(1, 3), p(0, 1), p(0, 6), p(0, 2)]);
|
|
|
- const a1 = AtomSet.create([p(1, 3), p(0, 1), p(0, 6), p(0, 2)]);
|
|
|
- const b = AtomSet.create([p(10, 3), p(0, 1), p(0, 6), p(4, 2)]);
|
|
|
- const c = AtomSet.create([p(1, 3)]);
|
|
|
- const d = AtomSet.create([p(2, 3)]);
|
|
|
- const e = AtomSet.create([p(0, 2)]);
|
|
|
+ const a = AtomSet.ofAtoms([p(1, 3), p(0, 1), p(0, 6), p(0, 2)], AtomSet.Empty);
|
|
|
+ const a1 = AtomSet.ofAtoms([p(1, 3), p(0, 1), p(0, 6), p(0, 2)], AtomSet.Empty);
|
|
|
+ const b = AtomSet.ofAtoms([p(10, 3), p(0, 1), p(0, 6), p(4, 2)], AtomSet.Empty);
|
|
|
+ const c = AtomSet.ofAtoms([p(1, 3)], AtomSet.Empty);
|
|
|
+ const d = AtomSet.ofAtoms([p(2, 3)], AtomSet.Empty);
|
|
|
+ const e = AtomSet.ofAtoms([p(0, 2)], AtomSet.Empty);
|
|
|
expect(setToPairs(AtomSet.subtract(a, a))).toEqual([]);
|
|
|
expect(setToPairs(AtomSet.subtract(a, a1))).toEqual([]);
|
|
|
expect(setToPairs(AtomSet.subtract(a, b))).toEqual([p(0, 2), p(1, 3)]);
|
|
@@ -141,17 +186,17 @@ describe('atom set', () => {
|
|
|
});
|
|
|
|
|
|
it('union', () => {
|
|
|
- const a = AtomSet.create([p(1, 3), p(0, 1)]);
|
|
|
- const a1 = AtomSet.create([p(1, 3), p(0, 1)]);
|
|
|
- const b = AtomSet.create([p(10, 3), p(0, 1)]);
|
|
|
- const c = AtomSet.create([p(1, 3)]);
|
|
|
- const d = AtomSet.create([p(2, 3)]);
|
|
|
- expect(AtomSet.unionMany([a])).toBe(a);
|
|
|
- expect(AtomSet.union(a, a)).toBe(a);
|
|
|
- expect(setToPairs(AtomSet.union(a, a))).toEqual([p(0, 1), p(1, 3)]);
|
|
|
- expect(setToPairs(AtomSet.union(a, a1))).toEqual([p(0, 1), p(1, 3)]);
|
|
|
- expect(setToPairs(AtomSet.union(a, b))).toEqual([p(0, 1), p(1, 3), p(10, 3)]);
|
|
|
- expect(setToPairs(AtomSet.union(c, d))).toEqual([p(1, 3), p(2, 3)]);
|
|
|
- expect(setToPairs(AtomSet.unionMany([a, b, c, d]))).toEqual([p(0, 1), p(1, 3), p(2, 3), p(10, 3)]);
|
|
|
+ const a = AtomSet.ofAtoms([p(1, 3), p(0, 1)], AtomSet.Empty);
|
|
|
+ const a1 = AtomSet.ofAtoms([p(1, 3), p(0, 1)], AtomSet.Empty);
|
|
|
+ const b = AtomSet.ofAtoms([p(10, 3), p(0, 1)], AtomSet.Empty);
|
|
|
+ const c = AtomSet.ofAtoms([p(1, 3)], AtomSet.Empty);
|
|
|
+ const d = AtomSet.ofAtoms([p(2, 3)], AtomSet.Empty);
|
|
|
+ expect(AtomSet.union([a], AtomSet.Empty)).toBe(a);
|
|
|
+ expect(AtomSet.union([a, a], AtomSet.Empty)).toBe(a);
|
|
|
+ expect(setToPairs(AtomSet.union([a, a], AtomSet.Empty))).toEqual([p(0, 1), p(1, 3)]);
|
|
|
+ expect(setToPairs(AtomSet.union([a, a1], AtomSet.Empty))).toEqual([p(0, 1), p(1, 3)]);
|
|
|
+ expect(setToPairs(AtomSet.union([a, b], AtomSet.Empty))).toEqual([p(0, 1), p(1, 3), p(10, 3)]);
|
|
|
+ expect(setToPairs(AtomSet.union([c, d], AtomSet.Empty))).toEqual([p(1, 3), p(2, 3)]);
|
|
|
+ expect(setToPairs(AtomSet.union([a, b, c, d], AtomSet.Empty))).toEqual([p(0, 1), p(1, 3), p(2, 3), p(10, 3)]);
|
|
|
});
|
|
|
});
|