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
afd3bfcb
authored
5 years ago
by
李楚霏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
task3 --提取字符串常量
parent
e02e29ff
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
35 deletions
+37
-35
length/src/index.js
+13
-11
length/src/index.test.js
+24
-24
No files found.
length/src/index.js
View file @
afd3bfcb
export
class
Length
{
value
unit
// unitEnum = ['foot', 'yard', 'inch']
static
FOOT
=
'foot'
static
YARD
=
'yard'
static
INCH
=
'inch'
constructor
(
val
,
uint
)
{
this
.
value
=
val
...
...
@@ -10,33 +12,33 @@ export class Length {
getVal
()
{
return
this
.
value
}
}
getUint
()
{
return
this
.
unit
}
parseTo
(
unitNode
)
{
let
unitLength
=
this
if
(
this
.
unit
===
'yard'
)
{
if
(
unitNode
===
'f'
)
{
if
(
this
.
unit
===
Length
.
YARD
)
{
if
(
unitNode
===
Length
.
FOOT
)
{
unitLength
=
new
Length
(
this
.
value
*
3
,
unitNode
)
}
else
if
(
unitNode
===
'inch'
)
{
}
else
if
(
unitNode
===
Length
.
INCH
)
{
unitLength
=
new
Length
(
this
.
value
*
36
,
unitNode
)
}
}
if
(
this
.
unit
===
'inch'
)
{
if
(
unitNode
===
'yard'
)
{
if
(
this
.
unit
===
Length
.
INCH
)
{
if
(
unitNode
===
Length
.
YARD
)
{
unitLength
=
new
Length
(
this
.
value
/
36
,
unitNode
)
}
else
if
(
unitNode
===
'f'
)
{
}
else
if
(
unitNode
===
Length
.
FOOT
)
{
unitLength
=
new
Length
(
this
.
value
/
12
,
unitNode
)
}
}
if
(
this
.
unit
===
'f'
)
{
if
(
unitNode
===
'yard'
)
{
if
(
this
.
unit
===
Length
.
FOOT
)
{
if
(
unitNode
===
Length
.
YARD
)
{
unitLength
=
new
Length
(
this
.
value
/
3
,
unitNode
)
}
else
if
(
unitNode
===
'inch'
)
{
}
else
if
(
unitNode
===
Length
.
INCH
)
{
unitLength
=
new
Length
(
this
.
value
*
12
,
unitNode
)
}
}
...
...
This diff is collapsed.
Click to expand it.
length/src/index.test.js
View file @
afd3bfcb
...
...
@@ -2,65 +2,65 @@ import { Length } from './index'
describe
(
'Length'
,
()
=>
{
it
(
"should 1 'foot' equals 1 'foot'"
,
()
=>
{
const
length
=
new
Length
(
1
,
'f'
)
const
length
=
new
Length
(
1
,
Length
.
FOOT
)
expect
(
length
.
getVal
()).
toEqual
(
1
)
expect
(
length
.
getUint
()).
toEqual
(
'f'
)
expect
(
length
.
getUint
()).
toEqual
(
Length
.
FOOT
)
})
it
(
"should 1 'foot' equals 12 inches"
,
()
=>
{
const
result
=
new
Length
(
1
,
'f'
).
parseTo
(
'inch'
)
const
result
=
new
Length
(
1
,
Length
.
FOOT
).
parseTo
(
Length
.
INCH
)
expect
(
result
.
getVal
()).
toEqual
(
12
)
expect
(
result
.
getUint
()).
toEqual
(
'inch'
)
expect
(
result
.
getUint
()).
toEqual
(
Length
.
INCH
)
})
it
(
"should 3 feet equals 1
'yard'
"
,
()
=>
{
const
result
=
new
Length
(
3
,
'f'
).
parseTo
(
'yard'
)
it
(
"should 3 feet equals 1
Length.YARD
"
,
()
=>
{
const
result
=
new
Length
(
3
,
Length
.
FOOT
).
parseTo
(
Length
.
YARD
)
expect
(
result
.
getVal
()).
toEqual
(
1
)
expect
(
result
.
getUint
()).
toEqual
(
'yard'
)
expect
(
result
.
getUint
()).
toEqual
(
Length
.
YARD
)
})
it
(
"should 1
'yard'
equals 3 feet"
,
()
=>
{
const
result
=
new
Length
(
1
,
'yard'
).
parseTo
(
'f'
)
it
(
"should 1
Length.YARD
equals 3 feet"
,
()
=>
{
const
result
=
new
Length
(
1
,
Length
.
YARD
).
parseTo
(
Length
.
FOOT
)
expect
(
result
.
getVal
()).
toEqual
(
3
)
expect
(
result
.
getUint
()).
toEqual
(
'f'
)
expect
(
result
.
getUint
()).
toEqual
(
Length
.
FOOT
)
})
it
(
"should 1
'yard'
equals 36 inches"
,
()
=>
{
const
result
=
new
Length
(
1
,
'yard'
).
parseTo
(
'inch'
)
it
(
"should 1
Length.YARD
equals 36 inches"
,
()
=>
{
const
result
=
new
Length
(
1
,
Length
.
YARD
).
parseTo
(
Length
.
INCH
)
expect
(
result
.
getVal
()).
toEqual
(
36
)
expect
(
result
.
getUint
()).
toEqual
(
'inch'
)
expect
(
result
.
getUint
()).
toEqual
(
Length
.
INCH
)
})
it
(
"should 1
'yard' equals 1 'yard'
"
,
()
=>
{
const
result
=
new
Length
(
1
,
'yard'
).
parseTo
(
'yard'
)
it
(
"should 1
Length.YARD equals 1 Length.YARD
"
,
()
=>
{
const
result
=
new
Length
(
1
,
Length
.
YARD
).
parseTo
(
Length
.
YARD
)
expect
(
result
.
getVal
()).
toEqual
(
1
)
expect
(
result
.
getUint
()).
toEqual
(
'yard'
)
expect
(
result
.
getUint
()).
toEqual
(
Length
.
YARD
)
})
it
(
"should 12 inches equals 1 'foot'"
,
()
=>
{
const
result
=
new
Length
(
12
,
'inch'
).
parseTo
(
'f'
)
const
result
=
new
Length
(
12
,
Length
.
INCH
).
parseTo
(
Length
.
FOOT
)
expect
(
result
.
getVal
()).
toEqual
(
1
)
expect
(
result
.
getUint
()).
toEqual
(
'f'
)
expect
(
result
.
getUint
()).
toEqual
(
Length
.
FOOT
)
})
it
(
"should 36 inches equals 1
'yard'
"
,
()
=>
{
const
result
=
new
Length
(
36
,
'inch'
).
parseTo
(
'yard'
)
it
(
"should 36 inches equals 1
yard
"
,
()
=>
{
const
result
=
new
Length
(
36
,
Length
.
INCH
).
parseTo
(
Length
.
YARD
)
expect
(
result
.
getVal
()).
toEqual
(
1
)
expect
(
result
.
getUint
()).
toEqual
(
'yard'
)
expect
(
result
.
getUint
()).
toEqual
(
Length
.
YARD
)
})
it
(
"should 1 inch equals 1
'inch'
"
,
()
=>
{
const
result
=
new
Length
(
1
,
'inch'
).
parseTo
(
'inch'
)
it
(
"should 1 inch equals 1
inch
"
,
()
=>
{
const
result
=
new
Length
(
1
,
Length
.
INCH
).
parseTo
(
Length
.
INCH
)
expect
(
result
.
getVal
()).
toEqual
(
1
)
expect
(
result
.
getUint
()).
toEqual
(
'inch'
)
expect
(
result
.
getUint
()).
toEqual
(
Length
.
INCH
)
})
})
This diff is collapsed.
Click to expand it.
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