- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassByValueTest.java
More file actions
Latest commit
54 lines (35 loc) · 1.01 KB
/
Copy pathPassByValueTest.java
File metadata and controls
54 lines (35 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
packagebasic;
importbasic.model.Foo;
importorg.junit.jupiter.api.Assertions;
importorg.junit.jupiter.api.Test;
publicclassPassByValueTest {
@Test
publicvoid원시타입은_함수에서수정해도_원본값은변하지_않는다() {
intx = 1;
inty = 2;
Assertions.assertEquals(x,1);
Assertions.assertEquals(y,2);
modify(x,y);
Assertions.assertEquals(x,1);
Assertions.assertEquals(y,2);
}
@Test
publicvoid참조타입은_함수에서수정하면_원본값이변한다() {
Fooa = newFoo(1);
Foob = newFoo(1);
Assertions.assertEquals(a.num,1);
Assertions.assertEquals(b.num,1);
modify(a,b);
Assertions.assertEquals(a.num,2);
Assertions.assertEquals(b.num,1);
}
publicstaticvoidmodify(Fooa1, Foob1) {
a1.num++;
b1 = newFoo(1);
b1.num++;
}
publicstaticvoidmodify(intx1, inty1) {
x1 = 5;
y1= 10;
}
}