Skip to content

Commit

Permalink
chore: add example test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Feb 16, 2024
1 parent a3288f2 commit f89d065
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cspell.config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '0.2'
version: "0.2"
ignorePaths:
- node_modules
- coverage
Expand All @@ -7,8 +7,18 @@ ignorePaths:
dictionaryDefinitions: []
dictionaries: []
words:
- alexiosc
- apollographql
- aspnetboiler
- aspnetboilerplate
- bitjson
- caddyserver
- coverallsapp
- exonum
- gitbucket
- histo
- logiciel
- megistos
- thistogram
ignoreWords: []
import: []
68 changes: 68 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,74 @@ describe('histogram', () => {
Dec ┃ ┣━●━━━━━━━━━┫ ┃ 3 ┃ 2 ┃ 7`.replace(/^\s+/gm, ''),
);
});

test.only('point-min-max temperature with custom headers', () => {
const d = `
AdaDoom3/AdaDoom3 ┃ 1.012 ┃ 0.991 ┃ 1.009
alexiosc/megistos ┃ 0.996 ┃ 0.963 ┃ 1.037
apollographql/apollo-server ┃ 1.031 ┃ 0.975 ┃ 1.047
aspnetboilerplate/aspnetboiler ┃ 1.025 ┃ 0.999 ┃ 1.001
aws-amplify/docs ┃ 1.05 ┃ 0.977 ┃ 1.023
Azure/azure-rest-api-specs ┃ 1.031 ┃ 0.986 ┃ 1.014
bitjson/typescript-starter ┃ 1.028 ┃ 0.987 ┃ 1.013
caddyserver/caddy ┃ 0.993 ┃ 0.988 ┃ 1.012
canada-ca/open-source-logiciel ┃ 1.103 ┃ 0.996 ┃ 1.004
chef/chef ┃ 0.983 ┃ 0.99 ┃ 1.01
django/django ┃ 0.986 ┃ 0.991 ┃ 1.009
eslint/eslint ┃ 0.891 ┃ 0.913 ┃ 1.087
exonum/exonum ┃ 1.021 ┃ 0.99 ┃ 1.01
gitbucket/gitbucket ┃ 1.092 ┃ 0.996 ┃ 1.004
googleapis/google-cloud-cpp ┃ 0.995 ┃ 0.938 ┃ 1.055
graphql/express-graphql ┃ 0.982 ┃ 0.994 ┃ 1.005
`;

const data: Data = d
.split('\n')
.map((a) => a.trim())
.filter((a) => !!a)
.map((line) => line.split('┃').map((a) => a.trim()))
.map(([label, value, min, max]) => [label, parseFloat(value), parseFloat(min), parseFloat(max)] as const);

const maxVal = data.reduce((curr, [, value, min, max]) => Math.max(curr, value, min ?? 1, max ?? 1), 1);
const minVal = data.reduce((curr, [, value, min, max]) => Math.min(curr, value, min ?? 1, max ?? 1), 1);
const maxDiff = Math.max(Math.abs(maxVal - 1), Math.abs(minVal - 1));

expect(
histogram(data, {
width: 100,
maxLabelWidth: 30,
title: 'Performance Deviation',
type: 'point-min-max',
headers: ['Repo', 'Val', 'Min', 'Max'],
max: 1 + maxDiff * 1.1,
min: 1 - maxDiff * 1.1,
}),
).toBe(
`\
Performance Deviation
Repo ┃ ┃ Val ┃ Min ┃ Max
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━╋━━━━━━━╋━━━━━━
AdaDoom3/AdaDoom3 ┃ ┣━━━● ┃ 1.012 ┃ 0.991 ┃ 1.009
alexiosc/megistos ┃ ┣━━━━━●━━━━━━━┫ ┃ 0.996 ┃ 0.963 ┃ 1.037
apollographql/apollo-server ┃ ┣━━━━━━━━━━●━━┫ ┃ 1.031 ┃ 0.975 ┃ 1.047
aspnetboilerplate/aspnetboiler ┃ ┫ ● ┃ 1.025 ┃ 0.999 ┃ 1.001
aws-amplify/docs ┃ ┣━━━━━━━┫ ● ┃ 1.05 ┃ 0.977 ┃ 1.023
Azure/azure-rest-api-specs ┃ ┣━━━━━┫ ● ┃ 1.031 ┃ 0.986 ┃ 1.014
bitjson/typescript-starter ┃ ┣━━━┫ ● ┃ 1.028 ┃ 0.987 ┃ 1.013
caddyserver/caddy ┃ ┣●━━┫ ┃ 0.993 ┃ 0.988 ┃ 1.012
canada-ca/open-source-logiciel ┃ ┣━┫ ● ┃ 1.103 ┃ 0.996 ┃ 1.004
chef/chef ┃ ●┣━━━┫ ┃ 0.983 ┃ 0.99 ┃ 1.01
django/django ┃ ●┣━━━┫ ┃ 0.986 ┃ 0.991 ┃ 1.009
eslint/eslint ┃ ● ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ ┃ 0.891 ┃ 0.913 ┃ 1.087
exonum/exonum ┃ ┣━━━┫ ● ┃ 1.021 ┃ 0.99 ┃ 1.01
gitbucket/gitbucket ┃ ┣━┫ ● ┃ 1.092 ┃ 0.996 ┃ 1.004
googleapis/google-cloud-cpp ┃ ┣━━━━━━━━━●━━━━━━━━━━┫ ┃ 0.995 ┃ 0.938 ┃ 1.055
graphql/express-graphql ┃ ● ┣━┫ ┃ 0.982 ┃ 0.994 ┃ 1.005`.replace(
/^\s+/gm,
'',
),
);
});
});

function sampleData(num: number, scale = 1, step = 5): Data {
Expand Down

0 comments on commit f89d065

Please sign in to comment.