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

[wip] bemCell algebra #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions benchmark/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ const decls = {
[{ block: 'block-2' }]
],
blockMods: [
[{ block: 'block', modName: 'bool-mod', modVal: true }],
[{ block: 'block', modName: 'mod', modVal: 'val-1' }],
[{ block: 'block', modName: 'mod', modVal: 'val-2' }]
[{ block: 'block', mod: { name: 'bool-mod', val: true } }],
[{ block: 'block', mod: { name: 'mod', val: 'val-1' } }],
[{ block: 'block', mod: { name: 'mod', val: 'val-2' } }]
],
elems: [
[{ block: 'block', elem: 'elem-1' }],
[{ block: 'block', elem: 'elem-2' }]
],
elemMods: [
[{ block: 'block', elem: 'elem' , modName: 'bool-mod', modVal: true }],
[{ block: 'block', elem: 'elem' , modName: 'mod', modVal: 'val-1' }],
[{ block: 'block', elem: 'elem' , modName: 'mod', modVal: 'val-2' }]
[{ block: 'block', elem: 'elem' , mod: { name: 'bool-mod', val: true } }],
[{ block: 'block', elem: 'elem' , mod: { name: 'mod', val: 'val-1' } }],
[{ block: 'block', elem: 'elem' , mod: { name: 'mod', val: 'val-2' } }]
]
};

Expand Down
12 changes: 6 additions & 6 deletions benchmark/normalize-harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const decls = {
{ block: 'block-3' }
],
blockMods: [
{ block: 'block-1', modName: 'mod' },
{ block: 'block-2', modName: 'mod', modVal: true },
{ block: 'block-3', modName: 'mod', modVal: 'val' },
{ block: 'block-1', mod: { name: 'mod' },
{ block: 'block-2', mod: { name: 'mod', val: true } },
{ block: 'block-3', mod: { name: 'mod', val: 'val' } },
{ block: 'block-4', mods: { mod: 'val' } },
{ block: 'block-5', mods: ['mod-1', 'mod-2'] },
{ block: 'block-6', mods: { mod: ['val-1', 'val-2'] } }
Expand All @@ -24,9 +24,9 @@ const decls = {
{ block: 'block', elems: ['elem-1', 'elem-2'] }
],
elemMods: [
{ block: 'block-1', elem: 'elem', modName: 'mod' },
{ block: 'block-2', elem: 'elem', modName: 'mod', modVal: true },
{ block: 'block-3', elem: 'elem', modName: 'mod', modVal: 'val' },
{ block: 'block-1', elem: 'elem', mod: { name: 'mod' },
{ block: 'block-2', elem: 'elem', mod: { name: 'mod', val: true } },
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zxqfox здесь так
{ block: 'block-2', elem: 'elem', modName: 'mod', modVal: true },
или так
{ block: 'block-2', elem: 'elem', mod: { name: 'mod', val: true } },

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше harmony вообще не трогать :-)

{ block: 'block-3', elem: 'elem', mod: { name: 'mod', val: 'val' } },
{ block: 'block-4', elem: 'elem', mods: { mod: 'val' } },
{ block: 'block-5', elem: 'elem', mods: ['mod-1', 'mod-2'] },
{ block: 'block-6', elem: 'elem', mods: { mod: ['val-1', 'val-2'] } }
Expand Down
166 changes: 83 additions & 83 deletions test/assign.test.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/format/enb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test('should coformatnvert with elem', t => {
test('should format with mod', t => {
t.deepEqual(
format([
{ entity: { block: 'block', modName: 'mod', modVal: 'val' }, tech: null }
{ entity: { block: 'block', mod: { name: 'mod', val: 'val' } }, tech: null }
], { format: 'enb' }),
[{ block: 'block', mod: 'mod', val: 'val' }]
)
Expand Down
48 changes: 24 additions & 24 deletions test/intersect/disjoint-entities.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@ const intersect = require('../../lib/intersect');
test('should not intersect other entities from block', t => {
const decl1 = [{ entity: { block: 'block' }, tech: null }].map(createCell);
const decl2 = [
{ entity: { block: 'block', modName: 'mod', modVal: true }, tech: null },
{ entity: { block: 'block', modName: 'mod', modVal: 'val' }, tech: null },
{ entity: { block: 'block', mod: { name: 'mod', val: true } }, tech: null },
{ entity: { block: 'block', mod: { name: 'mod', val: 'val' } }, tech: null },
{ entity: { block: 'block', elem: 'elem' }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: true }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: 'val' }, tech: null }
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: true } }, tech: null },
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: 'val' } }, tech: null }
].map(createCell);

t.deepEqual(intersect(decl1, decl2), []);
});

test('should not intersect other entities from bool mod', t => {
const decl1 = [{ entity: { block: 'block', modName: 'mod', modVal: true }, tech: null }].map(createCell);
const decl1 = [{ entity: { block: 'block', mod: { name: 'mod', val: true } }, tech: null }].map(createCell);
const decl2 = [
{ entity: { block: 'block' }, tech: null },
{ entity: { block: 'block', modName: 'mod', modVal: 'val' }, tech: null },
{ entity: { block: 'block', mod: { name: 'mod', val: 'val' } }, tech: null },
{ entity: { block: 'block', elem: 'elem' }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: true }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: 'val' }, tech: null }
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: true } }, tech: null },
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: 'val' } }, tech: null }
].map(createCell);

t.deepEqual(intersect(decl1, decl2), []);
});

test('should not intersect other entities from mod', t => {
const decl1 = [{ entity: { block: 'block', modName: 'mod', modVal: 'val' }, tech: null }].map(createCell);
const decl1 = [{ entity: { block: 'block', mod: { name: 'mod', val: 'val' } }, tech: null }].map(createCell);
const decl2 = [
{ entity: { block: 'block' }, tech: null },
{ entity: { block: 'block', modName: 'mod', modVal: true }, tech: null },
{ entity: { block: 'block', mod: { name: 'mod', val: true } }, tech: null },
{ entity: { block: 'block', elem: 'elem' }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: true }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: 'val' }, tech: null }
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: true } }, tech: null },
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: 'val' } }, tech: null }
].map(createCell);

t.deepEqual(intersect(decl1, decl2), []);
Expand All @@ -48,40 +48,40 @@ test('should not intersect other entities from elem', t => {
const decl1 = [{ entity: { block: 'block', elem: 'elem' }, tech: null }].map(createCell);
const decl2 = [
{ entity: { block: 'block' }, tech: null },
{ entity: { block: 'block', modName: 'mod', modVal: true }, tech: null },
{ entity: { block: 'block', modName: 'mod', modVal: 'val' }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: true }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: 'val' }, tech: null },
{ entity: { block: 'block', mod: { name: 'mod', val: true } }, tech: null },
{ entity: { block: 'block', mod: { name: 'mod', val: 'val' } }, tech: null },
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: true } }, tech: null },
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: 'val' } }, tech: null },
].map(createCell);

t.deepEqual(intersect(decl1, decl2), []);
});

test('should not intersect other entities from bool mod of elem', t => {
const decl1 = [
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: true }, tech: null }
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: true } }, tech: null }
].map(createCell);
const decl2 = [
{ entity: { block: 'block' }, tech: null },
{ entity: { block: 'block', modName: 'mod', modVal: true }, tech: null },
{ entity: { block: 'block', modName: 'mod', modVal: 'val' }, tech: null },
{ entity: { block: 'block', mod: { name: 'mod', val: true } }, tech: null },
{ entity: { block: 'block', mod: { name: 'mod', val: 'val' } }, tech: null },
{ entity: { block: 'block', elem: 'elem' }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: 'val' }, tech: null }
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: 'val' } }, tech: null }
].map(createCell);

t.deepEqual(intersect(decl1, decl2), []);
});

test('should not intersect other entities from mod of elem', t => {
const decl1 = [
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: 'val' }, tech: null }
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: 'val' } }, tech: null }
].map(createCell);
const decl2 = [
{ entity: { block: 'block' }, tech: null },
{ entity: { block: 'block', modName: 'mod', modVal: true }, tech: null },
{ entity: { block: 'block', modName: 'mod', modVal: 'val' }, tech: null },
{ entity: { block: 'block', mod: { name: 'mod', val: true } }, tech: null },
{ entity: { block: 'block', mod: { name: 'mod', val: 'val' } }, tech: null },
{ entity: { block: 'block', elem: 'elem' }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: true }, tech: null }
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: true } }, tech: null }
].map(createCell);

t.deepEqual(intersect(decl1, decl2), []);
Expand Down
8 changes: 4 additions & 4 deletions test/intersect/intersecting-entities.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ test('should intersect block with block', t => {
});

test('should intersect bool mod with bool mod', t => {
const mod = [{ entity: { block: 'block', modName: 'mod', modVal: true }, tech: null }].map(createCell);
const mod = [{ entity: { block: 'block', mod: { name: 'mod', val: true } }, tech: null }].map(createCell);

t.deepEqual(intersect(mod, mod), mod);
});

test('should intersect mod with mod', t => {
const mod = [{ entity: { block: 'block', modName: 'mod', modVal: 'val' }, tech: null }].map(createCell);
const mod = [{ entity: { block: 'block', mod: { name: 'mod', val: 'val' } }, tech: null }].map(createCell);

t.deepEqual(intersect(mod, mod), mod);
});
Expand All @@ -30,15 +30,15 @@ test('should intersect elem with elem', t => {

test('should intersect bool mod of elem with bool mod of elem', t => {
const mod = [
{ entity: { block: 'block', elem: 'elem' , modName: 'mod', modVal: true }, tech: null }
{ entity: { block: 'block', elem: 'elem' , mod: { name: 'mod', val: true } }, tech: null }
].map(createCell);

t.deepEqual(intersect(mod, mod), mod);
});

test('should intersect elem mod with elem mod', t => {
const mod = [
{ entity: { block: 'block', elem: 'elem' , modName: 'mod', modVal: 'val' }, tech: null }
{ entity: { block: 'block', elem: 'elem' , mod: { name: 'mod', val: 'val' } }, tech: null }
].map(createCell);

t.deepEqual(intersect(mod, mod), mod);
Expand Down
20 changes: 10 additions & 10 deletions test/merge/bem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ test('should merge block with its elem', t => {

test('should merge block with its mod', t => {
const block = [{ entity: { block: 'block' } }].map(createCell);
const mod = [{ entity: { block: 'block', modName: 'mod', modVal: 'val' } }].map(createCell);
const mod = [{ entity: { block: 'block', mod: { name: 'mod', val: 'val' } } }].map(createCell);

t.deepEqual(merge(block, mod), [].concat(block, mod));
});

test('should merge block with its bool mod', t => {
const block = [{ entity: { block: 'block' } }].map(createCell);
const mod = [{ entity: { block: 'block', modName: 'mod', modVal: true } }].map(createCell);
const mod = [{ entity: { block: 'block', mod: { 'mod', val: true } } }].map(createCell);

t.deepEqual(merge(block, mod), [].concat(block, mod));
});
Expand All @@ -39,36 +39,36 @@ test('should merge elems of block', t => {
});

test('should merge mods of block', t => {
const mod1 = [{ entity: { block: 'block', modName: 'mod-1', modVal: true } }].map(createCell);
const mod2 = [{ entity: { block: 'block', modName: 'mod-2', modVal: true } }].map(createCell);
const mod1 = [{ entity: { block: 'block', mod: { name: 'mod-1', val: true } } }].map(createCell);
const mod2 = [{ entity: { block: 'block', mod: { name: 'mod-2', val: true } } }].map(createCell);

t.deepEqual(merge(mod1, mod2), [].concat(mod1, mod2));
});

test('should merge mod vals of block mod', t => {
const val1 = [{ entity: { block: 'block', modName: 'mod', modVal: 'val-1' } }].map(createCell);
const val2 = [{ entity: { block: 'block', modName: 'mod', modVal: 'val-2' } }].map(createCell);
const val1 = [{ entity: { block: 'block', mod: { name: 'mod', val: 'val-1' } } }].map(createCell);
const val2 = [{ entity: { block: 'block', mod: { name: 'mod', val: 'val-2' } } }].map(createCell);

t.deepEqual(merge(val1, val2), [].concat(val1, val2));
});

test('should merge elem with its mod', t => {
const elem = [{ entity: { block: 'block', elem: 'elem' } }].map(createCell);
const mod = [{ entity: { block: 'block', elem: 'elem' , modName: 'mod', modVal: 'val' } }].map(createCell);
const mod = [{ entity: { block: 'block', elem: 'elem' , mod: { name: 'mod', val: 'val' } } }].map(createCell);

t.deepEqual(merge(elem, mod), [].concat(elem, mod));
});

test('should merge elem with its bool mod', t => {
const elem = [{ entity: { block: 'block', elem: 'elem' } }].map(createCell);
const mod = [{ entity: { block: 'block', elem: 'elem' , modName: 'mod', modVal: true } }].map(createCell);
const mod = [{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: true } } }].map(createCell);

t.deepEqual(merge(elem, mod), [].concat(elem, mod));
});

test('should merge mods of elem', t => {
const mod1 = [{ entity: { block: 'block', elem: 'elem', modName: 'mod-1', modVal: true } }].map(createCell);
const mod2 = [{ entity: { block: 'block', elem: 'elem', modName: 'mod-2', modVal: true } }].map(createCell);
const mod1 = [{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod-1', val: true } } }].map(createCell);
const mod2 = [{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod-2', val: true } } }].map(createCell);

t.deepEqual(merge(mod1, mod2), [].concat(mod1, mod2));
});
Expand Down
20 changes: 10 additions & 10 deletions test/normalize-harmony/elem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ test('should support shortcut for bool mod of elem', t => {
t.deepEqual(normalize(decl).map(simplifyCell), [
{ entity: { block: 'block' }, tech: null },
{ entity: { block: 'block', elem: 'elem' }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: true }, tech: null }
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: true } }, tech: null }
]);
});

test('should support bool mod of elem', t => {
const decl = { block: 'block', elem: 'elem', modName: 'mod', modVal: true };
const decl = { block: 'block', elem: 'elem', mod: { name: 'mod', val: true } };

t.deepEqual(normalize(decl).map(simplifyCell), [
{ entity: { block: 'block' }, tech: null },
{ entity: { block: 'block', elem: 'elem' }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: true }, tech: null }
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: true } }, tech: null }
]);
});

test('should support elem mod', t => {
const decl = { block: 'block', elem: 'elem', modName: 'mod', modVal: 'val' };
const decl = { block: 'block', elem: 'elem', mod: { name: 'mod', val: 'val' } };

t.deepEqual(normalize(decl).map(simplifyCell), [
{ entity: { block: 'block' }, tech: null },
{ entity: { block: 'block', elem: 'elem' }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: 'val' }, tech: null }
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: 'val' } }, tech: null }
]);
});

Expand All @@ -53,7 +53,7 @@ test('should support elem mods as object', t => {
t.deepEqual(normalize(decl).map(simplifyCell), [
{ entity: { block: 'block' }, tech: null },
{ entity: { block: 'block', elem: 'elem' }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: 'val' }, tech: null }
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: 'val' } }, tech: null }
]);
});

Expand All @@ -67,8 +67,8 @@ test('should support bool mods of elem as array', t => {
t.deepEqual(normalize(decl).map(simplifyCell), [
{ entity: { block: 'block' }, tech: null },
{ entity: { block: 'block', elem: 'elem' }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod-1', modVal: true }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod-2', modVal: true }, tech: null }
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod-1', val: true } }, tech: null },
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod-2', val: true } }, tech: null }
]);
});

Expand All @@ -82,7 +82,7 @@ test('should support mod values of elem as array', t => {
t.deepEqual(normalize(decl).map(simplifyCell), [
{ entity: { block: 'block' }, tech: null },
{ entity: { block: 'block', elem: 'elem' }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: 'val-1' }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: 'val-2' }, tech: null }
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: 'val-1' } }, tech: null },
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: 'val-2' } }, tech: null }
]);
});
2 changes: 1 addition & 1 deletion test/normalize-harmony/elems.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ test('should support mods for elem objects', t => {
t.deepEqual(normalize(decl).map(simplifyCell), [
{ entity: { block: 'block' }, tech: null },
{ entity: { block: 'block', elem: 'elem' }, tech: null },
{ entity: { block: 'block', elem: 'elem', modName: 'mod', modVal: 'val' }, tech: null }
{ entity: { block: 'block', elem: 'elem', mod: { name: 'mod', val: 'val' } }, tech: null }
]);
});
4 changes: 2 additions & 2 deletions test/normalize-harmony/mix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('should support mix', t => {
{ entity: { block: 'block' }, tech: null },
{ entity: { block: 'block', elem: 'elem-1' }, tech: null },
{ entity: { block: 'block', elem: 'elem-2' }, tech: null },
{ entity: { block: 'block', modName: 'mod-1', modVal: true }, tech: null },
{ entity: { block: 'block', modName: 'mod-2', modVal: true }, tech: null }
{ entity: { block: 'block', mod: { name: 'mod-1', val: true } }, tech: null },
{ entity: { block: 'block', mod: { name: 'mod-2', val: true } }, tech: null }
]);
});
Loading