Skip to content

Commit fce9777

Browse files
committed
add jest test.
1 parent f08dcd3 commit fce9777

File tree

4 files changed

+73
-62
lines changed

4 files changed

+73
-62
lines changed

.babelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
presets: [
3+
"es2015"
4+
]
5+
}

implements.js

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,75 +10,72 @@ Math.avg = function(...a){
1010

1111
const { sin, cos, PI, sqrt, pow, max, min, round, random, sum, avg } = Math;
1212

13-
export default class calculateMethods {
14-
15-
/*
16-
* Get a dot coordinate on the given circle
17-
* All of these params are necessary for generating.
18-
* @param deg should in radian( 2*PI ) format.NOT angle( 360° ).
19-
*
20-
**/
21-
22-
static getCirclePoint(
23-
radius : Number = 0,
24-
originX : Number = 0,
25-
originY : Number = 0,
26-
deg : Number = 0
27-
){
28-
29-
return {
30-
x:radius*cos( PI/2 - deg ) + originX,
31-
y:-radius*sin( PI/2 - deg ) + originY
32-
}
13+
/*
14+
* Get a dot coordinate on the given circle
15+
* All of these params are necessary for generating.
16+
* @param deg should in radian( 2*PI ) format.NOT angle( 360° ).
17+
*
18+
**/
19+
20+
export function getCirclePoint(
21+
radius = 0,
22+
originX = 0,
23+
originY = 0,
24+
deg = 0
25+
){
26+
27+
return {
28+
x:radius*cos( PI/2 - deg ) + originX,
29+
y:-radius*sin( PI/2 - deg ) + originY
3330
}
31+
}
3432

35-
/*
36-
* Convert angle number to raduan number.
37-
**/
33+
/*
34+
* Convert angle number to raduan number.
35+
**/
3836

39-
static angleToRadian( angle :Number = 0 ){
40-
return angle/180*PI
41-
}
37+
export function angleToRadian( angle = 0 ){
38+
return angle/180*PI
39+
}
4240

4341

44-
/*
45-
* Mathod to varify whether dot withing a sector filed.
46-
**/
47-
48-
static isDotWithinPie(
49-
radius : Number = 0,
50-
originX : Number = 0,
51-
originY : Number = 0,
52-
shapeDeg : Number = 0,
53-
pointX : Number = 0,
54-
pointY : Number = 0,
55-
startDeg : Number = 0,
56-
endDeg : Number = 0
57-
){
58-
const pointDelta = sqrt( pow(pointX - originX,2) + pow(pointY - originY,2) );
59-
const deg = ( pointX - originX / radius )
60-
}
42+
/*
43+
* Mathod to varify whether dot withing a sector filed.
44+
**/
45+
46+
export function isDotWithinPie(
47+
radius = 0,
48+
originX = 0,
49+
originY = 0,
50+
shapeDeg = 0,
51+
pointX = 0,
52+
pointY = 0,
53+
startDeg = 0,
54+
endDeg = 0
55+
){
56+
const pointDelta = sqrt( pow(pointX - originX,2) + pow(pointY - originY,2) );
57+
const deg = ( pointX - originX / radius )
58+
}
6159

62-
/*
63-
* Get a larger 10ex number of given number array to be y axis range.
64-
**/
60+
/*
61+
* Get a larger 10ex number of given number array to be y axis range.
62+
**/
6563

66-
static roundingRange(
67-
datas : Array = []
68-
){
69-
if( !datas.length ) return;
64+
export function roundingRange(
65+
datas = []
66+
){
67+
if( !datas.length ) return;
7068

71-
const maxValue = max.apply(null,datas)
72-
const minValue = min.apply(null,datas)
69+
const maxValue = max.apply(null,datas)
70+
const minValue = min.apply(null,datas)
7371

74-
const maxValueLength = ( '' + maxValue ).length
75-
const minValueLength = ( '' + minValue ).length
72+
const maxValueLength = ( '' + maxValue ).length
73+
const minValueLength = ( '' + minValue ).length
7674

77-
const delta = maxValueLength - minValueLength;
78-
const deltaRound = pow(10,delta);
75+
const delta = maxValueLength - minValueLength;
76+
const deltaRound = pow(10,delta);
7977

80-
return (
81-
parseInt(maxValue/deltaRound) + 1
82-
)*deltaRound;
83-
}
78+
return (
79+
parseInt(maxValue/deltaRound) + 1
80+
)*deltaRound;
8481
}

implements.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const { roundingRange } = require('./implements');
2+
3+
test('adds 1 + 2 to equal 3', () => {
4+
expect(roundingRange([100,2001])).toBe(2010);
5+
});

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "animate chart library for react-native,based on react-native ART module.",
55
"main": "main.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "jest"
88
},
99
"repository": {
1010
"type": "git",
@@ -25,5 +25,9 @@
2525
"bugs": {
2626
"url": "https://github.com/react-native-china/react-native-animate-chart/issues"
2727
},
28-
"homepage": "https://github.com/react-native-china/react-native-animate-chart#readme"
28+
"homepage": "https://github.com/react-native-china/react-native-animate-chart#readme",
29+
"devDependencies": {
30+
"babel-preset-es2015": "^6.22.0",
31+
"jest": "^18.1.0"
32+
}
2933
}

0 commit comments

Comments
 (0)