Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
李楚霏
/
refactorTest
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
11022629
authored
Jan 28, 2020
by
李楚霏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
task4--改变函数参数
parent
afd3bfcb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
34 deletions
+33
-34
length/src/index.js
+10
-12
length/src/index.test.js
+23
-22
No files found.
length/src/index.js
View file @
11022629
import
*
as
Constants
from
'./constants'
export
class
Length
{
value
unit
static
FOOT
=
'foot'
static
YARD
=
'yard'
static
INCH
=
'inch'
constructor
(
val
,
uint
)
{
this
.
value
=
val
...
...
@@ -19,26 +17,26 @@ export class Length {
}
parseTo
(
unitNode
)
{
let
unitLength
=
this
if
(
this
.
unit
===
Length
.
YARD
)
{
if
(
unitNode
===
Length
.
FOOT
)
{
if
(
this
.
unit
===
Constants
.
Constants
.
YARD
)
{
if
(
unitNode
===
Constants
.
Constants
.
FOOT
)
{
unitLength
=
new
Length
(
this
.
value
*
3
,
unitNode
)
}
else
if
(
unitNode
===
Length
.
INCH
)
{
}
else
if
(
unitNode
===
Constants
.
Constants
.
INCH
)
{
unitLength
=
new
Length
(
this
.
value
*
36
,
unitNode
)
}
}
if
(
this
.
unit
===
Length
.
INCH
)
{
if
(
unitNode
===
Length
.
YARD
)
{
if
(
this
.
unit
===
Constants
.
Constants
.
INCH
)
{
if
(
unitNode
===
Constants
.
Constants
.
YARD
)
{
unitLength
=
new
Length
(
this
.
value
/
36
,
unitNode
)
}
else
if
(
unitNode
===
Length
.
FOOT
)
{
}
else
if
(
unitNode
===
Constants
.
Constants
.
FOOT
)
{
unitLength
=
new
Length
(
this
.
value
/
12
,
unitNode
)
}
}
if
(
this
.
unit
===
Length
.
FOOT
)
{
if
(
unitNode
===
Length
.
YARD
)
{
if
(
this
.
unit
===
Constants
.
Constants
.
FOOT
)
{
if
(
unitNode
===
Constants
.
Constants
.
YARD
)
{
unitLength
=
new
Length
(
this
.
value
/
3
,
unitNode
)
}
else
if
(
unitNode
===
Length
.
INCH
)
{
}
else
if
(
unitNode
===
Constants
.
Constants
.
INCH
)
{
unitLength
=
new
Length
(
this
.
value
*
12
,
unitNode
)
}
}
...
...
length/src/index.test.js
View file @
11022629
import
{
Length
}
from
'./index'
import
{
Constants
}
from
'./constants'
describe
(
'Length'
,
()
=>
{
it
(
"should 1 'foot' equals 1 'foot'"
,
()
=>
{
const
length
=
new
Length
(
1
,
Length
.
FOOT
)
const
length
=
new
Length
(
1
,
Constants
.
FOOT
)
expect
(
length
.
getVal
()).
toEqual
(
1
)
expect
(
length
.
getUint
()).
toEqual
(
Length
.
FOOT
)
expect
(
length
.
getUint
()).
toEqual
(
Constants
.
FOOT
)
})
it
(
"should 1 'foot' equals 12 inches"
,
()
=>
{
const
result
=
new
Length
(
1
,
Length
.
FOOT
).
parseTo
(
Length
.
INCH
)
const
result
=
new
Length
(
1
,
Constants
.
FOOT
).
parseTo
(
Constants
.
INCH
)
expect
(
result
.
getVal
()).
toEqual
(
12
)
expect
(
result
.
getUint
()).
toEqual
(
Length
.
INCH
)
expect
(
result
.
getUint
()).
toEqual
(
Constants
.
INCH
)
})
it
(
"should 3 feet equals 1
Length.YARD
"
,
()
=>
{
const
result
=
new
Length
(
3
,
Length
.
FOOT
).
parseTo
(
Length
.
YARD
)
it
(
"should 3 feet equals 1
yard
"
,
()
=>
{
const
result
=
new
Length
(
3
,
Constants
.
FOOT
).
parseTo
(
Constants
.
YARD
)
expect
(
result
.
getVal
()).
toEqual
(
1
)
expect
(
result
.
getUint
()).
toEqual
(
Length
.
YARD
)
expect
(
result
.
getUint
()).
toEqual
(
Constants
.
YARD
)
})
it
(
"should 1
Length
.YARD equals 3 feet"
,
()
=>
{
const
result
=
new
Length
(
1
,
Length
.
YARD
).
parseTo
(
Length
.
FOOT
)
it
(
"should 1
Constants
.YARD equals 3 feet"
,
()
=>
{
const
result
=
new
Length
(
1
,
Constants
.
YARD
).
parseTo
(
Constants
.
FOOT
)
expect
(
result
.
getVal
()).
toEqual
(
3
)
expect
(
result
.
getUint
()).
toEqual
(
Length
.
FOOT
)
expect
(
result
.
getUint
()).
toEqual
(
Constants
.
FOOT
)
})
it
(
"should 1
Length
.YARD equals 36 inches"
,
()
=>
{
const
result
=
new
Length
(
1
,
Length
.
YARD
).
parseTo
(
Length
.
INCH
)
it
(
"should 1
Constants
.YARD equals 36 inches"
,
()
=>
{
const
result
=
new
Length
(
1
,
Constants
.
YARD
).
parseTo
(
Constants
.
INCH
)
expect
(
result
.
getVal
()).
toEqual
(
36
)
expect
(
result
.
getUint
()).
toEqual
(
Length
.
INCH
)
expect
(
result
.
getUint
()).
toEqual
(
Constants
.
INCH
)
})
it
(
"should 1
Length.YARD equals 1 Length
.YARD"
,
()
=>
{
const
result
=
new
Length
(
1
,
Length
.
YARD
).
parseTo
(
Length
.
YARD
)
it
(
"should 1
Constants.YARD equals 1 Constants
.YARD"
,
()
=>
{
const
result
=
new
Length
(
1
,
Constants
.
YARD
).
parseTo
(
Constants
.
YARD
)
expect
(
result
.
getVal
()).
toEqual
(
1
)
expect
(
result
.
getUint
()).
toEqual
(
Length
.
YARD
)
expect
(
result
.
getUint
()).
toEqual
(
Constants
.
YARD
)
})
it
(
"should 12 inches equals 1 'foot'"
,
()
=>
{
const
result
=
new
Length
(
12
,
Length
.
INCH
).
parseTo
(
Length
.
FOOT
)
const
result
=
new
Length
(
12
,
Constants
.
INCH
).
parseTo
(
Constants
.
FOOT
)
expect
(
result
.
getVal
()).
toEqual
(
1
)
expect
(
result
.
getUint
()).
toEqual
(
Length
.
FOOT
)
expect
(
result
.
getUint
()).
toEqual
(
Constants
.
FOOT
)
})
it
(
"should 36 inches equals 1 yard"
,
()
=>
{
const
result
=
new
Length
(
36
,
Length
.
INCH
).
parseTo
(
Length
.
YARD
)
const
result
=
new
Length
(
36
,
Constants
.
INCH
).
parseTo
(
Constants
.
YARD
)
expect
(
result
.
getVal
()).
toEqual
(
1
)
expect
(
result
.
getUint
()).
toEqual
(
Length
.
YARD
)
expect
(
result
.
getUint
()).
toEqual
(
Constants
.
YARD
)
})
it
(
"should 1 inch equals 1 inch"
,
()
=>
{
const
result
=
new
Length
(
1
,
Length
.
INCH
).
parseTo
(
Length
.
INCH
)
const
result
=
new
Length
(
1
,
Constants
.
INCH
).
parseTo
(
Constants
.
INCH
)
expect
(
result
.
getVal
()).
toEqual
(
1
)
expect
(
result
.
getUint
()).
toEqual
(
Length
.
INCH
)
expect
(
result
.
getUint
()).
toEqual
(
Constants
.
INCH
)
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment