pitest
This commit is contained in:
parent
75448022dd
commit
59be76cf17
4 changed files with 208 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
artist.txt
|
artist.txt
|
||||||
.idea/
|
.idea/
|
||||||
target/
|
target/
|
||||||
|
*.iml
|
||||||
|
|
134
SQ-2021-H6/pom.xml
Normal file
134
SQ-2021-H6/pom.xml
Normal file
|
@ -0,0 +1,134 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.usi.sq</groupId>
|
||||||
|
<artifactId>SQ-2021-H6</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<junit.platform.version>1.7.0-M1</junit.platform.version>
|
||||||
|
<junit.jupiter.version>5.6.2</junit.jupiter.version>
|
||||||
|
<junit.vintage.version>5.6.2</junit.vintage.version>
|
||||||
|
<junit.version>4.13.1</junit.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>3.0.0-M5</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>8</source>
|
||||||
|
<target>8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jacoco</groupId>
|
||||||
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
|
<version>0.8.5</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>prepare-agent</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<!-- attached to Maven test phase -->
|
||||||
|
<execution>
|
||||||
|
<id>report</id>
|
||||||
|
<phase>test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>report</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.pitest</groupId>
|
||||||
|
<artifactId>pitest-maven</artifactId>
|
||||||
|
<version>1.5.2</version>
|
||||||
|
<configuration>
|
||||||
|
<targetClasses>
|
||||||
|
<param>org.usi.sq.util*</param>
|
||||||
|
</targetClasses>
|
||||||
|
<targetTests>
|
||||||
|
<param>org.usi.sq.util*</param>
|
||||||
|
<param>*</param>
|
||||||
|
</targetTests>
|
||||||
|
</configuration>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.pitest</groupId>
|
||||||
|
<artifactId>pitest-junit5-plugin</artifactId>
|
||||||
|
<version>0.12</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<version>${junit.jupiter.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>${junit.jupiter.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>${junit.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.vintage</groupId>
|
||||||
|
<artifactId>junit-vintage-engine</artifactId>
|
||||||
|
<version>${junit.vintage.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<reporting>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jacoco</groupId>
|
||||||
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
|
<reportSets>
|
||||||
|
<reportSet>
|
||||||
|
<reports>
|
||||||
|
<!-- select non-aggregate reports -->
|
||||||
|
<report>report</report>
|
||||||
|
</reports>
|
||||||
|
</reportSet>
|
||||||
|
</reportSets>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-report-plugin</artifactId>
|
||||||
|
<version>3.0.0-M5</version>
|
||||||
|
<configuration>
|
||||||
|
<!-- place configuration here if required-->
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jxr-plugin</artifactId>
|
||||||
|
<version>2.1</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</reporting>
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,40 @@
|
||||||
|
package org.usi.sq.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CollectionUtils {
|
||||||
|
|
||||||
|
private static final double EPSILON = 1e-6;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of insertion sort. Insertion sort can be used in cases
|
||||||
|
* where the input list is almost sorted or small. The list implementation
|
||||||
|
* should provide fast indexed access. Due to its quadratic worst-case
|
||||||
|
* runtime complexity, other sorting algorithms should be used in the
|
||||||
|
* general case.
|
||||||
|
*
|
||||||
|
* @param list the list to be sorted in-place
|
||||||
|
* @param <T> the type of the elements in the list (need to be comparable)
|
||||||
|
* @throws IllegalArgumentException if called with null pointer
|
||||||
|
*/
|
||||||
|
static <T extends Comparable<T>> void sort(List<T> list){
|
||||||
|
if(list == null)
|
||||||
|
throw new IllegalArgumentException("Sort must not be called with " +
|
||||||
|
"null");
|
||||||
|
for(int i = 1; i < list.size(); i++){
|
||||||
|
T key = list.get(i);
|
||||||
|
int j = 0;
|
||||||
|
for(j = i-1; j >= 0; j--){
|
||||||
|
T elem = list.get(j);
|
||||||
|
if(elem.compareTo(key) > 0){ // check if elem > key
|
||||||
|
list.set(j+1, elem);
|
||||||
|
} else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.set(j+1,key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package org.usi.sq.util;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
class CollectionUtilsTest {
|
||||||
|
|
||||||
|
private static <T extends Comparable<T>> void checkSort(List<T> source, List<T> expected) {
|
||||||
|
List<T> target = new ArrayList<>(source);
|
||||||
|
CollectionUtils.sort(target);
|
||||||
|
assertEquals(expected, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> List<T> list(T... elements) {
|
||||||
|
return Arrays.asList(elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> ArrayList<T> empty() {
|
||||||
|
return new ArrayList<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkSorted() {
|
||||||
|
checkSort(empty(), empty());
|
||||||
|
checkSort(list(0, 1, 2, 3, 4), list(0, 1, 2, 3, 4));
|
||||||
|
checkSort(list(8, 4, 5, 6, 7), list(4, 5, 6, 7, 8));
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue