-
Notifications
You must be signed in to change notification settings - Fork 27
任务1 单位转换 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
任务1 单位转换 #1
Changes from all commits
4ffca78
75c5a18
ab97540
ae9867f
8098271
27deb25
f39b80a
45dbad9
ea2f780
d4679d5
13da9a5
73d9fb6
b8c4418
9d35531
840bb41
882c832
c7dd84b
bc8e04e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| /** | ||
| * Created with IntelliJ IDEA. | ||
| * User: lai.yi | ||
| * Date: 2020/2/1 | ||
| * Description: | ||
| **/ | ||
| public enum Unit { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个模板可以配IDE让它不打出来的,这些信息从版本管理里面都能看到。 |
||
| FOOT, INCH, YARD | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,89 +6,89 @@ | |
| public class LengthTest { | ||
| @Test | ||
| public void should_1_inch_equals_1_inch() { | ||
| Length result = new Length(1, "inch").as("inch"); | ||
| Length result = new Length(1, Unit.INCH).as(Unit.INCH); | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在这个 27deb25 提交里,对 现在 看了你后面的提交,发觉其实你这么做也可以,挺好。就是剩下那个 |
||
| assertThat(result.getVal(), is(1.0)); | ||
| assertThat(result.getUinnt(), is("inch")); | ||
| assertThat(result.getUnit(), is(Unit.INCH)); | ||
| } | ||
|
|
||
| @Test | ||
| public void should_2_feet_equals_2_feet() { | ||
| Length result = new Length(2, "f").as("f"); | ||
| Length result = new Length(2, Unit.FOOT).as(Unit.FOOT); | ||
|
|
||
| assertThat(result.getVal(), is(2.0)); | ||
| assertThat(result.getUinnt(), is("f")); | ||
| assertThat(result.getUnit(), is(Unit.FOOT)); | ||
| } | ||
|
|
||
| @Test | ||
| public void should_1_yard_equals_1_yard() { | ||
| Length result = new Length(1, "yard").as("yard"); | ||
| Length result = new Length(1, Unit.YARD).as(Unit.YARD); | ||
|
|
||
| assertThat(result.getVal(), is(1.0)); | ||
| assertThat(result.getUinnt(), is("yard")); | ||
| assertThat(result.getUnit(), is(Unit.YARD)); | ||
| } | ||
|
|
||
| @Test | ||
| public void should_1_foot_equals_12_inches() { | ||
| Length result = new Length(1, "f").as("inch"); | ||
| Length result = new Length(1, Unit.FOOT).as(Unit.INCH); | ||
|
|
||
| assertThat(result.getVal(), is(12.0)); | ||
| assertThat(result.getUinnt(), is("inch")); | ||
| assertThat(result.getUnit(), is(Unit.INCH)); | ||
| } | ||
|
|
||
| @Test | ||
| public void should_3_foot_equals_1_yard() { | ||
| Length result = new Length(3, "f").as("yard"); | ||
| Length result = new Length(3, Unit.FOOT).as(Unit.YARD); | ||
|
|
||
| assertThat(result.getVal(), is(1.0)); | ||
| assertThat(result.getUinnt(), is("yard")); | ||
| assertThat(result.getUnit(), is(Unit.YARD)); | ||
| } | ||
|
|
||
| @Test | ||
| public void should_1_yard_equals_3_feet() { | ||
| Length result = new Length(1, "yard").as("f"); | ||
| Length result = new Length(1, Unit.YARD).as(Unit.FOOT); | ||
|
|
||
| assertThat(result.getVal(), is(3.0)); | ||
| assertThat(result.getUinnt(), is("f")); | ||
| assertThat(result.getUnit(), is(Unit.FOOT)); | ||
| } | ||
|
|
||
| @Test | ||
| public void should_1_yard_equals_36_inches() { | ||
| Length result = new Length(1, "yard").as("inch"); | ||
| Length result = new Length(1, Unit.YARD).as(Unit.INCH); | ||
|
|
||
| assertThat(result.getVal(), is(36.0)); | ||
| assertThat(result.getUinnt(), is("inch")); | ||
| assertThat(result.getUnit(), is(Unit.INCH)); | ||
| } | ||
|
|
||
| @Test | ||
| public void should_2_yards_equals_72_inches() { | ||
| Length result = new Length(2, "yard").as("inch"); | ||
| Length result = new Length(2, Unit.YARD).as(Unit.INCH); | ||
|
|
||
| assertThat(result.getVal(), is(72.0)); | ||
| assertThat(result.getUinnt(), is("inch")); | ||
| assertThat(result.getUnit(), is(Unit.INCH)); | ||
| } | ||
|
|
||
| @Test | ||
| public void should_12_inches_equals_1_foot() { | ||
| Length result = new Length(12, "inch").as("f"); | ||
| Length result = new Length(12, Unit.INCH).as(Unit.FOOT); | ||
|
|
||
| assertThat(result.getVal(), is(1.0)); | ||
| assertThat(result.getUinnt(), is("f")); | ||
| assertThat(result.getUnit(), is(Unit.FOOT)); | ||
| } | ||
|
|
||
| @Test | ||
| public void should_36_inches_equals_1_yard() { | ||
| Length result = new Length(36, "inch").as("yard"); | ||
| Length result = new Length(36, Unit.INCH).as(Unit.YARD); | ||
|
|
||
| assertThat(result.getVal(), is(1.0)); | ||
| assertThat(result.getUinnt(), is("yard")); | ||
| assertThat(result.getUnit(), is(Unit.YARD)); | ||
| } | ||
|
|
||
| @Test | ||
| public void should_18_inches_equals_half_yard() { | ||
| Length result = new Length(18, "inch").as("yard"); | ||
| Length result = new Length(18, Unit.INCH).as(Unit.YARD); | ||
|
|
||
| assertThat(result.getVal(), is(0.5)); | ||
| assertThat(result.getUinnt(), is("yard")); | ||
| assertThat(result.getUnit(), is(Unit.YARD)); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里删除
String targetUnit参数是用IDE删的吗?是的话就很标准做法,不然自己一步删步子就太大了哟。