package com.company;
public class Algorithm {
int a;
int b;
int c;
Algorithm swap(Algorithm algorithm) {
System.out.println("a = " + algorithm.a + " b = " + algorithm.b + " c = " + algorithm.c);
algorithm.a = algorithm.a + (algorithm.b + algorithm.c);
algorithm.b = algorithm.a - (algorithm.b + algorithm.c);
algorithm.c = algorithm.a - (algorithm.b + algorithm.c);
algorithm.a = algorithm.a - (algorithm.b + algorithm.c);
System.out.println("a = " + algorithm.a + " b = " + algorithm.b + " c = " + algorithm.c);
return algorithm;
}
}
package com.company;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class AlgorithmTest {
@Test
void swap1() {
Algorithm algorithm = new Algorithm();
algorithm.a = 10;
algorithm.b = 20;
algorithm.c = 30;
Algorithm swap = algorithm.swap(algorithm);
Assertions.assertEquals(30, swap.a);
Assertions.assertEquals(10, swap.b);
Assertions.assertEquals(20, swap.c);
}
}
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter:5.6.2')
}
test {
useJUnitPlatform()
}
package com.company;
public class Algorithm {
int a;
int b;
int c;
Algorithm swap(Algorithm algorithm) {
System.out.println("a = " + algorithm.a + " b = " + algorithm.b + " c = " + algorithm.c);
algorithm.a = algorithm.a ^ algorithm.b ^ algorithm.c;
algorithm.b = algorithm.a ^ algorithm.b ^ algorithm.c;
algorithm.c = algorithm.a ^ algorithm.b ^ algorithm.c;
algorithm.a = algorithm.a ^ algorithm.b ^ algorithm.c;
System.out.println("a = " + algorithm.a + " b = " + algorithm.b + " c = " + algorithm.c);
return algorithm;
}
}
package com.company;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class AlgorithmTest {
@Test
void swap1() {
Algorithm algorithm = new Algorithm();
algorithm.a = 10;
algorithm.b = 20;
algorithm.c = 30;
Algorithm swap = algorithm.swap(algorithm);
Assertions.assertEquals(30, swap.a);
Assertions.assertEquals(10, swap.b);
Assertions.assertEquals(20, swap.c);
}
}
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter:5.6.2')
}
test {
useJUnitPlatform()
}