Daniel Le Berre преди 6 години
ревизия
1b02fa5c02

+ 7 - 0
.classpath

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="lib" path="org.eclipse.jdt.annotation_2.2.200.v20180921-1416.jar"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 4 - 0
.gitignore

@@ -0,0 +1,4 @@
+bin
+.sonar
+build
+testreports

+ 13 - 0
.gitlab-ci.yml

@@ -0,0 +1,13 @@
+variables:
+  GIT_SUBMODULE_STRATEGY: recursive
+
+before_script: 
+   - "./checklinks.sh $CI_PROJECT_NAMESPACE"
+   - "git submodule update --remote --init"
+
+tests:
+   script: "ant -Detudiant=$CI_PROJECT_NAMESPACE sonar"
+   artifacts:
+     untracked: true
+   tags: 
+     - java

+ 17 - 0
.project

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>TDD2019IMPL</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 11 - 0
.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8

+ 142 - 0
build.xml

@@ -0,0 +1,142 @@
+<project name="tdd" default="tests" basedir="." xmlns:sonar="antlib:org.sonar.ant" xmlns:jacoco="antlib:org.jacoco.ant">
+	<property name="project.java.version" value="1.8" />
+	<property name="encoding" value="UTF-8" />
+	<property name="sonar.login" value="TOKEN SONAR ICI" />
+	<!-- LE RESTE DOIT ETRE BON -->
+	<property name="build" value="build" />
+	<property name="testreports" value="testreports" />
+	<property name="src" value="src" />
+
+	<!-- Define the SonarQube global properties (the most usual way is to pass these properties via the command line) -->
+	<property name="sonar.host.url" value="https://forge.univ-artois.fr/sonar67" />
+	<property name="sonar.projectKey" value="${etudiant}:2018:MyLisp" />
+	<property name="sonar.projectName" value="${etudiant} Lisp 18" />
+	<property name="sonar.projectVersion" value="1.0" />
+	<property name="sonar.java.source" value="${project.java.version}" />
+	<property name="sonar.java.binaries" value="build" />
+	<property name="sonar.java.libraries" value="lib/*.jar" />
+	<property name="sonar.sources" value="src" />
+	<property name="sonar.exclusions" value="**/*Test*" />
+	<property name="sonar.tests" value="TDD2018TESTS/src,TDD2018OWNTESTS/src" />
+	<property name="sonar.junit.reportPaths" value="${testreports}" />
+	<property name="sonar.jacoco.reportPath" value="${testreports}/jacoco.exec" />
+        <property name="sonar.pitest.reportsDirectory" value="${testreports}" />
+	<property name="sonar.web.javaAdditionalOpts" value="-Dhttps.proxyHost=cache-etu.univ-artois.fr -Dhttps.proxyPort=3128" />
+	<target name="prepare" description="Cree les repertoires et initialise certaines valeurs">
+		<!-- Create the time stamp -->
+		<tstamp />
+		<mkdir dir="${build}" />
+		<mkdir dir="${testreports}" />
+	</target>
+
+	<path id="mypath">
+		<pathelement location="${build}" />
+		<fileset dir="lib">
+			<include name="*.jar" />
+		</fileset>
+	</path>
+
+	<target name="build" description="Compile les fichiers Java" depends="prepare">
+		<javac includeantruntime="true" srcdir="${src}" destdir="${build}" source="${project.java.version}" debug="true" encoding="${encoding}">
+			<classpath refid="mypath" />
+		</javac>
+	</target>
+
+	<target name="clean" description="Efface tous les fichiers generes">
+		<!-- Delete directory trees -->
+		<delete dir="${build}" />
+		<delete dir="${testreports}" />
+		<delete dir="${target}" />
+	</target>
+
+	<target name="compilepublictests">
+		<echo>Compilation des tests publics</echo>
+		<javac includeantruntime="true" srcdir="TDD2018TESTS/src" destdir="${build}" source="${project.java.version}" debug="true" encoding="${encoding}">
+			<classpath refid="mypath" />
+		</javac>
+		<copy todir="${build}">
+			<fileset dir="TDD2018TESTS/src">
+				<include name="**/*.story" />
+			</fileset>
+		</copy>
+	</target>
+	<target name="compileprivatetests" if="private.tests.found">
+		<echo>Compilation des tests privés</echo>
+		<javac includeantruntime="true" srcdir="TDD2018HIDDENTESTS/src" destdir="${build}" source="${project.java.version}" debug="true" encoding="${encoding}">
+			<classpath refid="mypath" />
+		</javac>
+
+		<copy todir="${build}">
+			<fileset dir="TDD2018HIDDENTESTS/src">
+				<include name="**/*.story" />
+			</fileset>
+		</copy>
+	</target>
+	<target name="compileowntests">
+		<echo>Compilation des tests personnels</echo>
+		<javac includeantruntime="true" srcdir="TDD2018OWNTESTS/src" destdir="${build}" source="${project.java.version}" debug="true" encoding="${encoding}">
+			<classpath refid="mypath" />
+		</javac>
+
+		<copy todir="${build}">
+			<fileset dir="TDD2018OWNTESTS/src">
+				<include name="**/*.story" />
+			</fileset>
+		</copy>
+	</target>
+
+	<target name="tests" description="test de l'application web à l'aide de JUnit" depends="build">
+		<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
+			<classpath path="lib/jacocoant.jar" />
+		</taskdef>
+		<antcall target="compilepublictests" />
+		<available property="private.tests.found" file="TDD2018HIDDENTESTS/src" type="dir" />
+		<antcall target="compileprivatetests" />
+		<antcall target="compileowntests" />
+		<jacoco:coverage destfile="${sonar.jacoco.reportPath}">
+			<junit fork="yes" forkmode="once" printsummary="false" haltonfailure="no" failureproperty="tests.failure">
+				<classpath refid="mypath" />
+				<formatter type="plain" usefile="false" />
+				<formatter type="xml" />
+				<batchtest fork="yes" todir="${testreports}">
+					<fileset dir="${build}">
+						<include name="**/TDD*.class" />
+						<include name="**/*Test*.class" />
+						<include name="**/PeterNorvig*.class" />
+						<exclude name="**/AllTests.class" />
+						<exclude name="**/Abstract*.class" />
+					</fileset>
+				</batchtest>
+			</junit>
+		</jacoco:coverage>
+	</target>
+
+	<target name="m1" description="Verification des projets de TDD2018" depends="clean,build,tests" />
+
+	<!-- Define the SonarQube target -->
+	<target name="sonar" depends="m1" description="Analyse le code avec SonarQube">
+		<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
+			<classpath path="lib/sonarqube-ant-task-2.5.jar" />
+		</taskdef>
+		<!-- To avoid analyzing the tests -->
+		<delete dir="${build}" />
+		<mkdir dir="${build}" />
+		<antcall target="build" />
+		<!-- Execute the SonarQube analysis -->
+		<sonar:sonar />
+		<fail message="Il reste des tests qui ne passent pas !" if="tests.failure" />
+	</target>
+    <target name="mutationCoverage">
+        <taskdef name="pitest" classname="org.pitest.ant.PitestTask" classpathref="mypath" />
+        <pitest
+              pitClasspath="mypath"
+              classPath="mypath"
+              targetClasses="migl.*"
+              excludedClasses="*Test*,*Eval*"
+              targetTests="migl.*"
+              reportDir="${testreports}"
+              outputFormats="XML,HTML"
+              sourceDir="${src}"/>
+    </target>
+</project>
+

BIN
lib/commons-codec-1.11.jar


BIN
lib/commons-collections4-4.1.jar


BIN
lib/commons-io-2.5.jar


BIN
lib/commons-lang3-3.5.jar


BIN
lib/freemarker.jar


BIN
lib/hamcrest-core-1.3.jar


BIN
lib/jacocoant.jar


BIN
lib/jbehave-ant-4.1.jar


BIN
lib/jbehave-core-4.1-javadoc.jar


BIN
lib/jbehave-core-4.1.jar


BIN
lib/jbehave-junit-runner-1.2.1-20150529.081438-4.jar


BIN
lib/jscheme-7.2.jar


BIN
lib/junit-4.12.jar


BIN
lib/org.eclipse.jdt.annotation_2.1.100.v20170511-1408.jar


BIN
lib/paranamer-2.8.jar


BIN
lib/pitest-1.3.2.jar


BIN
lib/pitest-ant-1.3.2.jar


BIN
lib/pitest-command-line-1.3.2.jar


BIN
lib/pitest-entry-1.3.2.jar


BIN
lib/plexus-utils-3.0.24.jar


BIN
lib/qualinsight-plugins-sonarqube-smell-api-4.0.0.jar


BIN
lib/sonarqube-ant-task-2.5.jar


BIN
org.eclipse.jdt.annotation_2.2.200.v20180921-1416.jar


+ 117 - 0
src/migl/util/Cons.java

@@ -0,0 +1,117 @@
+package migl.util;
+
+/**
+ * Building block for implementing lists.
+ * 
+ * A "cons" is simply a pair (L,R) holding a specific value on the left hand
+ * side (L) and the right hand side (R).
+ * 
+ * See e.g. {@link https://en.wikipedia.org/wiki/Cons} for details.
+ * 
+ * @author leberre
+ *
+ * @param <L>
+ *            the type of the left hand side of the pair
+ * @param <R>
+ *            the type of the right hand side of the pair
+ */
+public class Cons<L, R> {
+
+    /**
+     * The left hand side of the pair.
+     */
+    private final L left;
+
+    /**
+     * The right hand side of the pair.
+     */
+    private final R right;
+
+    /**
+     * Private default constructor to prevent its use outside the class.
+     */
+    private Cons() {
+        this(null, null);
+    }
+
+    /**
+     * Generic constructor for the cons data structure.
+     * 
+     * @param left
+     *            the left hand side.
+     * @param right
+     *            the right hand side.
+     */
+    public Cons(L left, R right) {
+        this.left = left;
+        this.right = right;
+    }
+
+    /**
+     * Retrieve the left hand side of the pair.
+     * 
+     * @return the left hand side of the pair if any.
+     */
+    public L left() {
+        return left;
+    }
+
+    /**
+     * Retrieve the right hand side of the pair.
+     * 
+     * @return the right hand side of the pair if any.
+     */
+    public R right() {
+        return right;
+    }
+
+    /**
+     * Typical textual "dotted" representation of a cons : ( L . R ).
+     * 
+     * @return a dotted textual representation of the cons pair.
+     */
+    @Override
+    public String toString() {
+        return "(" + left + " . " + right + ")";
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((left == null) ? 0 : left.hashCode());
+        return prime * result + ((right == null) ? 0 : right.hashCode());
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        Cons<?, ?> other = (Cons<?, ?>) obj;
+        if (left == null) {
+            if (other.left != null)
+                return false;
+        } else if (!left.equals(other.left))
+            return false;
+        if (right == null) {
+            if (other.right != null)
+                return false;
+        } else if (!right.equals(other.right))
+            return false;
+        return true;
+    }
+
+    /**
+     * Uses type inference to build an empty cons of the expected type.
+     * 
+     * @return an empty cons of the expected type.
+     */
+    public static final <U, V> Cons<U, V> nil() {
+        return new Cons<>();
+    }
+
+}

+ 109 - 0
src/migl/util/ConsList.java

@@ -0,0 +1,109 @@
+package migl.util;
+
+import java.util.function.BinaryOperator;
+import java.util.function.Function;
+
+/**
+ * Implementation of a list using the {@link migl.util.Cons} data structure.
+ * 
+ * The implementation of ConsList must be immutable, i.e. each call to the
+ * {@link #append(Object)} or {@link #prepend(Object)} methods must return a new
+ * list without changing the state of the current list. This is unlike the
+ * default behavior of {@link java.util.List} behavior.
+ * 
+ * @author leberre
+ *
+ * @param <E>
+ *            the type of the elements in the list
+ */
+public interface ConsList<E> extends Iterable<E> {
+
+    /**
+     * Insert a new element e in front of the list.
+     * 
+     * @param e
+     *            an element.
+     * @return a new list containing e in front of the current one.
+     */
+    ConsList<E> prepend(E e);
+
+    /**
+     * Insert a new element e at the end of the list
+     * 
+     * @param e
+     *            an element
+     * @return a new list containing e at the end of the current one.
+     */
+    ConsList<E> append(E e);
+
+    /**
+     * Check if the list is empty or not.
+     * 
+     * @return true if the list is empty, else false.
+     */
+    boolean isEmpty();
+
+    /**
+     * Retrieve the first element of the list.
+     * 
+     * @return the first element of the list.
+     */
+    E car();
+
+    /**
+     * Return the sublist corresponding to all but the first element.
+     * 
+     * @return all but the first element of the list.
+     */
+    ConsList<E> cdr();
+
+    /**
+     * Returns the size of the list (the number of elements it contains).
+     * 
+     * @return the number of elements in the list.
+     */
+    int size();
+
+    /**
+     * Create a new list by applying a function to each element of the list.
+     * 
+     * @param f
+     *            a function
+     * @return a list where each element is the result of applying f to an element
+     *         of the original list.
+     */
+    <T> ConsList<T> map(Function<E, T> f);
+
+    /**
+     * Performs a reduction on the elements of this list, using the provided
+     * identity value and an associative accumulation function, and returns the
+     * reduced value.
+     * 
+     * @param identity
+     *            the identity value for the accumulating function
+     * @param accumulator
+     *            an associative, stateless function for combining two values
+     * @return the result of the reduction
+     */
+    default E reduce(E identity, BinaryOperator<E> accumulator) {
+        E result = identity;
+        for (E element : this) {
+            result = accumulator.apply(result, element);
+        }
+        return result;
+    }
+
+    /**
+     * Translates the ConsList as an array of Object. The type of the
+     * 
+     * @return all the elements of the list in an array of objects
+     */
+    default Object[] toArray() {
+        Object[] array = new Object[size()];
+        int i = 0;
+        for (Object o : this) {
+            array[i++] = o;
+        }
+        return array;
+    }
+}

+ 51 - 0
src/migl/util/ConsListFactory.java

@@ -0,0 +1,51 @@
+package migl.util;
+
+/**
+ * Factory to create new lists.
+ * 
+ * The methods take advantage of type inference to simplify the use of the
+ * methods in the user code.
+ * 
+ * The body of the methods must be completed by the students.
+ * 
+ * @author leberre
+ *
+ */
+public final class ConsListFactory {
+
+    private ConsListFactory() {
+        // do nothing
+    }
+
+    /**
+     * Create a new empty list.
+     * 
+     * @return an empty list
+     */
+    public static <T> ConsList<T> nil() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Create a new list containing a single element
+     * 
+     * @param t
+     *            an object
+     * @return a list containing only t
+     */
+    public static <T> ConsList<T> singleton(T t) {
+    	 throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Create a new list containing the elements given in parameter
+     * 
+     * @param ts
+     *            a variable number of elements
+     * @return a list containing those elements
+     */
+    @SafeVarargs
+    public static <T> ConsList<T> asList(T... ts) {
+    	 throw new UnsupportedOperationException();
+    }
+}