Skip to content

Commit

Permalink
Renamed the test, improve coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
yhoonkim committed Mar 29, 2017
1 parent 76fe75c commit 3c480e3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/constraint/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Channel} from 'vega-lite/build/src/channel';
import {channelCompatibility} from 'vega-lite/build/src/fielddef';
import {ScaleType, scaleTypeSupportProperty, hasDiscreteDomain, channelScalePropertyIncompatability, Scale} from 'vega-lite/build/src/scale';
import {Type} from 'vega-lite/build/src/type';
import {SortField} from 'vega-lite/build/src/sort';
import {SortField, isSortField} from 'vega-lite/build/src/sort';
import {AbstractConstraint, AbstractConstraintModel} from './base';

import {QueryConfig} from '../config';
Expand Down Expand Up @@ -376,13 +376,13 @@ export const FIELD_CONSTRAINTS: EncodingConstraintModel<FieldQuery>[] = [
return true;
}
},{
name: 'onlyCountWithAsteriskFieldOnSort',
name: 'onlyUseCountWithAsteriskSortField',
description: 'Sort by * if and only if op is count',
properties: [Property.SORT, getEncodingNestedProp('sort', 'field'), getEncodingNestedProp('sort', 'op')],
allowWildcardForProperties: false,
strict: true,
satisfy: (fieldQ: FieldQuery, _: Schema, __: PropIndex<Wildcard<any>>, ___: QueryConfig) => {
if (fieldQ.sort && !!(fieldQ.sort as SortField).field) {
if (fieldQ.sort && isSortField(fieldQ.sort)) {
return ((fieldQ.sort as SortField).field === '*') === ((fieldQ.sort as SortField).op === 'count');
}
return true;
Expand Down
14 changes: 8 additions & 6 deletions test/constraint/encoding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,20 +492,22 @@ describe('constraints/encoding', () => {
});
});

describe('onlyCountWithAutoCountFieldOnSort', () => {
describe('onlyUseCountWithAsteriskSortField', () => {
it('should allow sort with * if and only if count is op', () => {
const encQ: EncodingQuery = {channel: Channel.X, field: 'O', type: Type.ORDINAL};
assert.isTrue(FIELD_CONSTRAINT_INDEX['onlyUseCountWithAsteriskSortField'].satisfy(encQ, schema, new PropIndex<Wildcard<any>>(), defaultOpt));

const encQ: EncodingQuery = {channel: Channel.X, field: 'O', sort: {field: '*', op: 'count', order: 'ascending'}, type: Type.ORDINAL};
assert.isTrue(FIELD_CONSTRAINT_INDEX['onlyCountWithAutoCountFieldOnSort'].satisfy(encQ, schema, new PropIndex<Wildcard<any>>(), defaultOpt));
const encQ1: EncodingQuery = {channel: Channel.X, field: 'O', sort: {field: '*', op: 'count', order: 'ascending'}, type: Type.ORDINAL};
assert.isTrue(FIELD_CONSTRAINT_INDEX['onlyUseCountWithAsteriskSortField'].satisfy(encQ1, schema, new PropIndex<Wildcard<any>>(), defaultOpt));

const encQ2: EncodingQuery = {channel: Channel.X, field: 'O', sort: {field: '*', op: 'mean', order: 'ascending'}, type: Type.ORDINAL};
assert.isFalse(FIELD_CONSTRAINT_INDEX['onlyCountWithAutoCountFieldOnSort'].satisfy(encQ2, schema, new PropIndex<Wildcard<any>>(), defaultOpt));
assert.isFalse(FIELD_CONSTRAINT_INDEX['onlyUseCountWithAsteriskSortField'].satisfy(encQ2, schema, new PropIndex<Wildcard<any>>(), defaultOpt));

const encQ3: EncodingQuery = {channel: Channel.X, field: 'O', sort: {field: 'A', op: 'count', order: 'ascending'}, type: Type.ORDINAL};
assert.isFalse(FIELD_CONSTRAINT_INDEX['onlyCountWithAutoCountFieldOnSort'].satisfy(encQ3, schema, new PropIndex<Wildcard<any>>(), defaultOpt));
assert.isFalse(FIELD_CONSTRAINT_INDEX['onlyUseCountWithAsteriskSortField'].satisfy(encQ3, schema, new PropIndex<Wildcard<any>>(), defaultOpt));

const encQ4: EncodingQuery = {channel: Channel.X, field: 'O', sort: {field: 'A', op: 'mean', order: 'ascending'}, type: Type.ORDINAL};
assert.isTrue(FIELD_CONSTRAINT_INDEX['onlyCountWithAutoCountFieldOnSort'].satisfy(encQ4, schema, new PropIndex<Wildcard<any>>(), defaultOpt));
assert.isTrue(FIELD_CONSTRAINT_INDEX['onlyUseCountWithAsteriskSortField'].satisfy(encQ4, schema, new PropIndex<Wildcard<any>>(), defaultOpt));


});
Expand Down
6 changes: 5 additions & 1 deletion test/wildcard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Mark} from 'vega-lite/build/src/mark';

import {assert} from 'chai';
import {initWildcard, isWildcard, SHORT_WILDCARD, getDefaultName, getDefaultEnumValues} from '../src/wildcard';
import {DEFAULT_PROP_PRECEDENCE, toKey} from '../src/property';
import {DEFAULT_PROP_PRECEDENCE, toKey, isEncodingNestedProp} from '../src/property';
import {DEFAULT_QUERY_CONFIG} from '../src/config';

describe('wildcard', () => {
Expand Down Expand Up @@ -114,8 +114,12 @@ describe('wildcard', () => {
if (e === undefined) {
missing.push(toKey(prop));
}
if ((isEncodingNestedProp(prop) && prop.parent === 'sort' && prop.child === 'field')){
assert.deepEqual(e, ['a', 'b', '*']);
}
}
assert.equal(missing.length, 0, 'Properties with missing enum: ' + missing.join(','));
});
});
});

0 comments on commit 3c480e3

Please sign in to comment.