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
76118ee0
authored
Jan 21, 2020
by
李楚霏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重构第一步
parents
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
0 deletions
+112
-0
length/src/index.js
+46
-0
length/src/index.test.js
+66
-0
No files found.
length/src/index.js
0 → 100644
View file @
76118ee0
export
class
Length
{
value
unit
unitEnum
=
[
'foot'
,
'yard'
,
'inch'
]
constructor
(
val
,
uint
)
{
this
.
value
=
val
this
.
unit
=
uint
}
getVal
()
{
return
this
.
value
}
getUint
()
{
return
this
.
unit
}
parseTo
(
u
)
{
let
len
=
this
if
(
this
.
unit
===
'yard'
)
{
if
(
u
===
'f'
)
{
len
=
new
Length
(
this
.
value
*
3
,
u
)
}
else
if
(
u
===
'inch'
)
{
len
=
new
Length
(
this
.
value
*
36
,
u
)
}
}
if
(
this
.
unit
===
'inch'
)
{
if
(
u
===
'yard'
)
{
len
=
new
Length
(
this
.
value
/
36
,
u
)
}
else
if
(
u
===
'f'
)
{
len
=
new
Length
(
this
.
value
/
12
,
u
)
}
}
if
(
this
.
unit
===
'f'
)
{
if
(
u
===
'yard'
)
{
len
=
new
Length
(
this
.
value
/
3
,
u
)
}
else
if
(
u
===
'inch'
)
{
len
=
new
Length
(
this
.
value
*
12
,
u
)
}
}
return
len
}
}
length/src/index.test.js
0 → 100644
View file @
76118ee0
import
{
Length
}
from
'./index'
describe
(
'Length'
,
()
=>
{
it
(
"should 1 'foot' equals 1 'foot'"
,
()
=>
{
const
length
=
new
Length
(
1
,
'f'
)
expect
(
length
.
getVal
()).
toEqual
(
1
)
expect
(
length
.
getUint
()).
toEqual
(
'f'
)
})
it
(
"should 1 'foot' equals 12 inches"
,
()
=>
{
const
result
=
new
Length
(
1
,
'f'
).
parseTo
(
'inch'
)
expect
(
result
.
getVal
()).
toEqual
(
12
)
expect
(
result
.
getUint
()).
toEqual
(
'inch'
)
})
it
(
"should 3 feet equals 1 'yard'"
,
()
=>
{
const
result
=
new
Length
(
3
,
'f'
).
parseTo
(
'yard'
)
expect
(
result
.
getVal
()).
toEqual
(
1
)
expect
(
result
.
getUint
()).
toEqual
(
'yard'
)
})
it
(
"should 1 'yard' equals 3 feet"
,
()
=>
{
const
result
=
new
Length
(
1
,
'yard'
).
parseTo
(
'f'
)
expect
(
result
.
getVal
()).
toEqual
(
3
)
expect
(
result
.
getUint
()).
toEqual
(
'f'
)
})
it
(
"should 1 'yard' equals 36 inches"
,
()
=>
{
const
result
=
new
Length
(
1
,
'yard'
).
parseTo
(
'inch'
)
expect
(
result
.
getVal
()).
toEqual
(
36
)
expect
(
result
.
getUint
()).
toEqual
(
'inch'
)
})
it
(
"should 1 'yard' equals 1 'yard'"
,
()
=>
{
const
result
=
new
Length
(
1
,
'yard'
).
parseTo
(
'yard'
)
expect
(
result
.
getVal
()).
toEqual
(
1
)
expect
(
result
.
getUint
()).
toEqual
(
'yard'
)
})
it
(
"should 12 inches equals 1 'foot'"
,
()
=>
{
const
result
=
new
Length
(
12
,
'inch'
).
parseTo
(
'f'
)
expect
(
result
.
getVal
()).
toEqual
(
1
)
expect
(
result
.
getUint
()).
toEqual
(
'f'
)
})
it
(
"should 36 inches equals 1 'yard'"
,
()
=>
{
const
result
=
new
Length
(
36
,
'inch'
).
parseTo
(
'yard'
)
expect
(
result
.
getVal
()).
toEqual
(
1
)
expect
(
result
.
getUint
()).
toEqual
(
'yard'
)
})
it
(
"should 1 inch equals 1 'inch'"
,
()
=>
{
const
result
=
new
Length
(
1
,
'inch'
).
parseTo
(
'inch'
)
expect
(
result
.
getVal
()).
toEqual
(
1
)
expect
(
result
.
getUint
()).
toEqual
(
'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