Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider ce03b136 rédigé par Arnaud LANOIX's avatar Arnaud LANOIX
Parcourir les fichiers

init tp2

parent
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 1195 ajouts et 0 suppression
# qalgo.tp2.arbrebinaire
> **ATTENTION :** Si vous utilisez un PC de l'IUT, décommentez
> les 4 lignes `systemProp.http.proxyXXX`
> dans le fichier `gradle.properties` pour activer la configuration du proxy.
# Arbres binaires
Il va s'agir d'implémenter les méthodes permettant de manipuler facilement un arbre binaire défini par le
diagramme de classes suivant :
![](specifications/BinaryTree.svg)
Implémentez les méthodes dans l'ordre indiqué ; testez au fur-et-à-mesure.
plugins {
kotlin("jvm") version "1.9.21"
//kotlin("plugin.serialization") version "1.9.21"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.11.2")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.11.2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
}
tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(11)
}
\ No newline at end of file
kotlin.code.style=official
#systemProp.http.proxyHost=srv-proxy-etu-2.iut-nantes.univ-nantes.prive
#systemProp.http.proxyPort=3128
#systemProp.https.proxyHost=srv-proxy-etu-2.iut-nantes.univ-nantes.prive
#systemProp.https.proxyPort=3128
\ No newline at end of file
Fichier ajouté
#Wed Nov 13 14:04:24 CET 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
}
rootProject.name = "qalgo.tp2.arbrebinaire"
\ No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentStyleType="text/css" height="737px" preserveAspectRatio="none" style="width:988px;height:737px;background:#FFFFFF;" version="1.1" viewBox="0 0 988 737" width="988px" zoomAndPan="magnify"><defs/><g><!--cluster kotlin--><g id="cluster_kotlin"><path d="M727.64,73.93 L770.4144,73.93 A3.75,3.75 0 0 1 772.9144,76.43 L779.9144,96.4183 L930.64,96.4183 A2.5,2.5 0 0 1 933.14,98.9183 L933.14,195.54 A2.5,2.5 0 0 1 930.64,198.04 L727.64,198.04 A2.5,2.5 0 0 1 725.14,195.54 L725.14,76.43 A2.5,2.5 0 0 1 727.64,73.93 " fill="none" style="stroke:#000000;stroke-width:1.5;"/><line style="stroke:#000000;stroke-width:1.5;" x1="725.14" x2="779.9144" y1="96.4183" y2="96.4183"/><text fill="#000000" font-family="sans-serif" font-size="14" font-weight="bold" lengthAdjust="spacing" textLength="41.7744" x="729.14" y="89.4652">kotlin</text></g><!--class Iterable--><g id="elem_Iterable"><rect codeLine="8" fill="#F1F1F1" height="73.1094" id="Iterable" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="176.835" x="740.72" y="108.93"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="63.4453" x="784.0271" y="125.5316">&#171;interface&#187;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="51.1875" x="790.156" y="141.598">Iterable</text><rect fill="#FFFFFF" height="16.1328" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" width="24.7754" x="895.7796" y="105.93"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="7.5879" x="904.3733" y="118.5316">T</text><line style="stroke:#181818;stroke-width:0.5;" x1="741.72" x2="916.555" y1="149.5511" y2="149.5511"/><line style="stroke:#181818;stroke-width:0.5;" x1="741.72" x2="916.555" y1="157.5511" y2="157.5511"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="164.835" x="746.72" y="175.0863">+iterator() : Iterator&lt;T&gt;</text></g><!--class iBinaryTree--><g id="elem_iBinaryTree"><rect codeLine="12" fill="#F1F1F1" height="270.9688" id="iBinaryTree" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="290.9199" x="351.68" y="10"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="63.4453" x="451.9066" y="26.6016">&#171;interface&#187;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="75.79" x="445.7342" y="42.668">iBinaryTree</text><rect fill="#FFFFFF" height="16.1328" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" width="25.0215" x="620.5784" y="7"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="7.834" x="629.1722" y="19.6016">K</text><line style="stroke:#181818;stroke-width:0.5;" x1="352.68" x2="641.5999" y1="50.6211" y2="50.6211"/><line style="stroke:#181818;stroke-width:0.5;" x1="352.68" x2="641.5999" y1="58.6211" y2="58.6211"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="140.2461" x="357.68" y="76.1563">+isEmpty() : Boolean</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="74.0605" x="357.68" y="92.6445">+size(): Int</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="90.2412" x="357.68" y="109.1328">+height(): Int</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="99.832" x="357.68" y="125.6211">+nbLeafs(): Int</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="165.1699" x="357.68" y="142.1094">+inorderKeys(): List&lt;K&gt;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="174.7744" x="357.68" y="158.5977">+preorderKeys(): List&lt;K&gt;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="182.2188" x="357.68" y="175.0859">+postorderKeys(): List&lt;K&gt;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="207.5186" x="357.68" y="191.5742">+breadthOrderKeys(): List&lt;K&gt;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="261.8711" x="357.68" y="208.0625">+infixDepthFirstIterator(): Iterator&lt;K&gt;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="271.4756" x="357.68" y="224.5508">+prefixDepthFirstIterator(): Iterator&lt;K&gt;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="278.9199" x="357.68" y="241.0391">+postfixDepthFirstIterator(): Iterator&lt;K&gt;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="243.1406" x="357.68" y="257.5273">+breadthFirstIterator(): Iterator&lt;K&gt;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="70.3418" x="357.68" y="274.0156">+iterator()</text></g><!--class BinaryTree--><g id="elem_BinaryTree"><rect codeLine="30" fill="#F1F1F1" height="372.2539" id="BinaryTree" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="507.6123" x="243.33" y="357.97"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="71.7432" x="447.7538" y="376.5052">BinaryTree</text><rect fill="#FFFFFF" height="16.1328" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" width="25.0215" x="728.9208" y="354.97"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="7.834" x="737.5146" y="367.5716">K</text><line style="stroke:#181818;stroke-width:0.5;" x1="244.33" x2="749.9423" y1="384.4583" y2="384.4583"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="60.4844" x="249.33" y="401.9934">#key : K?</text><line style="stroke:#181818;stroke-width:0.5;" x1="244.33" x2="749.9423" y1="408.9466" y2="408.9466"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="91.6904" x="249.33" y="426.4817">&#171;create&#187; init()</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="137.416" x="249.33" y="442.97">&#171;create&#187; init(key : K)</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="253.5381" x="249.33" y="459.4583">&#171;create&#187; init(key : K, left : BinaryTree)</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="263.7373" x="249.33" y="475.9466">&#171;create&#187; init(key : K, right : BinaryTree)</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="379.8594" x="249.33" y="492.4348">&#171;create&#187; init(key : K, left : BinaryTree, right : BinaryTree)</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="140.2461" x="249.33" y="508.9231">+isEmpty() : Boolean</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="74.0605" x="249.33" y="525.4114">+size(): Int</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="90.2412" x="249.33" y="541.8997">+height(): Int</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="99.832" x="249.33" y="558.388">+nbLeafs(): Int</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="165.1699" x="249.33" y="574.8763">+inorderKeys(): List&lt;K&gt;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="174.7744" x="249.33" y="591.3645">+preorderKeys(): List&lt;K&gt;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="182.2188" x="249.33" y="607.8528">+postorderKeys(): List&lt;K&gt;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="207.5186" x="249.33" y="624.3411">+breadthOrderKeys(): List&lt;K&gt;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="495.6123" x="249.33" y="640.8294">#buildString(prefix: String, isLast: Boolean, isLeft: Boolean = true): String</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="127.2988" x="249.33" y="657.3177">+toString() : String</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="261.8711" x="249.33" y="673.8059">+infixDepthFirstIterator(): Iterator&lt;K&gt;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="271.4756" x="249.33" y="690.2942">+prefixDepthFirstIterator(): Iterator&lt;K&gt;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="278.9199" x="249.33" y="706.7825">+postfixDepthFirstIterator(): Iterator&lt;K&gt;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="243.1406" x="249.33" y="723.2708">+breadthFirstIterator(): Iterator&lt;K&gt;</text></g><!--class BinaryTreeException--><g id="elem_BinaryTreeException"><rect codeLine="53" fill="#F1F1F1" height="42.4883" id="BinaryTreeException" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="144.2705" x="7" y="522.85"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="138.2705" x="10" y="541.3852">BinaryTreeException</text><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="150.2705" y1="549.3383" y2="549.3383"/><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="150.2705" y1="557.3383" y2="557.3383"/></g><!--link iBinaryTree to Iterable--><g id="link_iBinaryTree_Iterable"><path codeLine="28" d="M642.76,145.48 C676.03,145.48 704.42,145.48 734.46,145.48 " fill="none" id="iBinaryTree-to-Iterable" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:7.0,7.0;"/><polygon fill="#181818" points="740.46,145.48,731.46,141.48,735.46,145.48,731.46,149.48,740.46,145.48" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="62.2007" x="660.66" y="139.0484">&#171;realizes&#187;</text></g><!--reverse link iBinaryTree to BinaryTree--><g id="link_iBinaryTree_BinaryTree"><path codeLine="55" d="M497.14,287.31 C497.14,311.9 497.14,331.95 497.14,357.7 " fill="none" id="iBinaryTree-backto-BinaryTree" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:7.0,7.0;"/><polygon fill="#181818" points="497.14,281.31,493.14,290.31,497.14,286.31,501.14,290.31,497.14,281.31" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="62.2007" x="498.14" y="324.5384">&#171;realizes&#187;</text></g><!--link BinaryTree to BinaryTree--><g id="link_BinaryTree_BinaryTree"><path codeLine="57" d="M751.08,527.74 C772.56,531.24 785.94,536.69 785.94,544.09 C785.94,551.5 778.4819,555.9851 757.0019,559.4851 " fill="none" id="BinaryTree-to-BinaryTree" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="751.08,560.45,760.6061,562.9505,756.0149,559.6459,759.3196,555.0547,751.08,560.45" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="116.2065" x="791.94" y="549.1584">has as left subtree</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="6.2651" x="758.712" y="524.6047">*</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="65.1714" x="762.8589" y="573.6561">0..1 -left</text></g><!--reverse link BinaryTree to BinaryTree--><g id="link_BinaryTree_BinaryTree"><path codeLine="59" d="M757.23,502.0019 C847.55,502.3319 917.94,516.34 917.94,544.09 C917.94,571.84 841.55,585.88 751.23,586.2 " fill="none" id="BinaryTree-backto-BinaryTree" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="751.23,501.98,760.2153,506.0129,756.23,501.9983,760.2446,498.0129,751.23,501.98" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="39.7935" x="927.8152" y="534.1584">has as</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="30.1133" x="936.7686" y="549.4689">right</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="47.5439" x="928.0533" y="564.7795">subtree</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="37.6353" x="759.3321" y="482.8619">-right</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="24.667" x="767.8728" y="498.1725">0..1</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="6.2651" x="758.8664" y="600.2456">*</text></g><!--reverse link BinaryTreeException to BinaryTree--><g id="link_BinaryTreeException_BinaryTree"><path codeLine="61" d="M157.47,544.09 C183.99,544.09 209.74,544.09 243.1,544.09 " fill="none" id="BinaryTreeException-backto-BinaryTree" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:7.0,7.0;"/><polygon fill="#181818" points="151.47,544.09,160.47,548.09,156.47,544.09,160.47,540.09,151.47,544.09" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="56.5005" x="169.3" y="537.6584">&#171;throws&#187;</text></g><!--SRC=[tLLDRzf04BtxLup8eT06bFOOkQuQDPKGI3s4Oo_hPS0ZpAwrErP2e_ptpYusCH-XvTXQlkoyDs_dqoveZg39wH8Jlo9JAQVMiBR6wiBPDGAxkeleKdd_bTbHNZEEjJKFz0lXfaF9bLujdQtDNDlIEdWiY35vzqe8O3Ks1JfYPJJ2foI9kh2oN98PZHcToajC0MO06QGf6J4jbCOiW-S4FW052blN7y0jZ9j3EikIbrQBxiWejvav33gJaphoY9I_NrUyYKftrfQeJ8DuIQq_47t3ZQL0MXQyRpFv5DN2xnl9M3T7Dy5D1ARaEPra3LWvF8TQpsVWtA6QS_7ZRGQP1JrzmugBx-GyZtUbwbIg6yibR8dj0deJwrymN_iPEjZf7OnSAFaeEnmEwLQQYdufJV9PrhQzuzcsVTleArZXHfmcN-8nJRKuSnW4CYGjFMbjNCw2rr3YWiFmxAx-0pzcT8d3qGLlQ_ntytm5UKtb_44-EMRPtuxhBMoFrvBiL7dU9HeDKgoT0Jx7BzYWzMWkPTleXIBj8V_MyhmSZ_tzavOBo1fu5hIxI7KbMzHThSCDwa2zzxtXCEl1pMZqKQ8PXWdimPvlhr0Uv8t3wUkSez-HIe15QHW7zgU9YWTAZP20BQcHsuy_A4a6fr8DcR3yi1v37hy1]--></g></svg>
\ No newline at end of file
package but3.collections
open class BinaryTree<K>(
protected var key: K? = null,
protected var left: BinaryTree<K>? = null,
protected var right: BinaryTree<K>? = null
) : iBinaryTree<K> {
override fun isEmpty(): Boolean {
TODO("1")
}
override fun size(): Int {
TODO("2 : OBLIGATOIREMENT de manière récursive")
}
override fun nbLeafs(): Int {
TODO("3 : OBLIGATOIREMENT de manière récursive")
}
override fun height(): Int {
TODO("4 : OBLIGATOIREMENT de manière récursive")
}
override fun inorderKeys(): List<K> {
TODO("5 : OBLIGATOIREMENT de manière récursive")
}
override fun preorderKeys(): List<K> {
TODO("6 : OBLIGATOIREMENT de manière récursive")
}
override fun postorderKeys(): List<K> {
TODO("7 : OBLIGATOIREMENT de manière récursive")
}
override fun breadthOrderKeys() =
if (isEmpty())
emptyList()
else
keysPerLevels(listOf(this))
/**
* Methode qui retourne la liste des valeurs contenues
* dans les arbres contenus dans la liste 'currenLevel'
* dans l'ordre du parcours en largeur
* @param currentLevel la liste des arbres à parcourir
* @return la liste des valeurs dans l'ordre du parcours en largeur.
*/
open protected fun keysPerLevels(currentLevel : List<BinaryTree<K>>) : List<K> {
TODO("8 : OBLIGATOIREMENT de manière récursive")
}
override fun toString() =
if (isEmpty())
"_"
else
buildString("", true)
/**
* Construit une représentation de l'arbre sous forme de chaîne de caractères
* @param prefix un préfixe à concaténer au début de la ligne
* @param isLast true si le sous-arbre courant est le dernier fils de son parent
* @param isLeft true si le sous-arbre courant est le fils gauche de son parent
*/
open protected fun buildString(
prefix: String,
isLast: Boolean,
isLeft: Boolean = true,
): String {
TODO("9 : OBLIGATOIREMENT de manière récursive")
}
override fun infixDepthFirstIterator(): Iterator<K> {
TODO("10 : en utilisant une pile pour empiler les sous-arbres à traiter lorsque l'on descend")
}
override fun prefixDepthFirstIterator(): Iterator<K> {
TODO("11 : en utilisant une pile pour empiler les sous-arbres à traiter lorsque l'on descend")
}
override fun postfixDepthFirstIterator(): Iterator<K> {
TODO("12 : en utilisant une pile pour empiler les sous-arbres à traiter lorsque l'on descend")
}
override fun breadthFirstIterator(): Iterator<K> {
TODO("13 : en utilisant une file pour mettre en attente les sous-arbres à traiter lorsque l'on descend")
}
}
package but3.collections
class BinaryTreeException : Exception() {
}
\ No newline at end of file
package but3.collections
interface iBinaryTree<K> : Iterable<K> {
/**
* Méthode qui teste si l'ABR est vide.
* @return vrai si l'ABR est vide ; faux sinon.
*/
fun isEmpty(): Boolean
/**
* Méthode RECURSIVE qui retourne le nombre d'elements contenus dans l'ABR.
* @return le nombre d'éléments contenus dans l'ABR
*/
fun size(): Int
/**
* Méthode RECURSIVE qui retourne le nombre de feuilles de l'ABR.
* @return le nombre de feuilles de l'ABR ; 0 si l'arbre est vide
*/
fun nbLeafs(): Int
/**
* Méthode RECURSIVE qui retourne la hauteur de l'ABR.
* @return la hauteur de l'ABR
*/
fun height(): Int
/**
* Methode qui retourne la liste des valeurs contenues dans l'ABR dans l'ordre infixé
* @return la liste des valeurs dans l'ordre infixé
*/
fun inorderKeys(): List<K>
/**
* Methode qui retourne la liste des valeurs contenues dans l'ABR dans l'ordre prefixé
* @return la liste des valeurs dans l'ordre préfixé
*/
fun preorderKeys(): List<K>
/**
* Methode qui retourne la liste des valeurs contenues dans l'ABR dans l'ordre postfixé
* @return la liste des valeurs dans l'ordre postfixé
*/
fun postorderKeys(): List<K>
/**
* Methode qui retourne la liste des valeurs contenues dans l'ABR dans l'ordre du parcours en largeur
* @return la liste des valeurs dans l'ordre du parcours en largeyr
*/
fun breadthOrderKeys(): List<K>
/**
*
* Méthode donnant une représentation de l'ABR sous la forme d'une chaîne de caractères
* @return une chaîne de caractères représentant l'iABR
*/
/**
* donne un iterateur réalisant un parcours (en profondeur) INFIXE de l'ABR
* @return un iterateur
*/
fun infixDepthFirstIterator(): Iterator<K>
/**
* donne un iterateur réalisant un parcours (en profondeur) PREFIXE sur l'ABR
* @return un iterateur
*/
fun prefixDepthFirstIterator(): Iterator<K>
/**
* donne un iterateur réalisant un parcours (en profondeur) POSTFIXE sur l'ABR
* @return un iterateur
*/
fun postfixDepthFirstIterator(): Iterator<K>
/**
* donne un iterateur réalisant un parcours en LARGEUR sur l'ABR
* @return un iterateur
*/
fun breadthFirstIterator(): Iterator<K>
/**
* donne un iterateur réalisant un parcours (en profondeur) INFIXE de l'ABR
* @return un iterateur
*/
override fun iterator() = infixDepthFirstIterator()
}
import but3.collections.BinaryTree
import but3.collections.BinaryTreeException
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
class Test1ArbreVide {
lateinit var tree : BinaryTree<String>
@BeforeEach
fun init() {
tree = InstBinaryTree()
InstBinaryTree.reinit()
}
@Test
fun testvide() {
assertTrue(tree.isEmpty())
assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testtaille() {
assertEquals(0, tree.size())
assertEquals(1, InstBinaryTree.recursiveCalls)
}
@Test
fun testhauteur() {
assertEquals(0, tree.height())
assertEquals(1, InstBinaryTree.recursiveCalls)
}
@Test
fun tesnbFeuilles() {
assertEquals(0, tree.nbLeafs())
assertEquals(1, InstBinaryTree.recursiveCalls)
}
@Test
fun testinorder() {
assertEquals(emptyList<String>(), tree.inorderKeys())
assertEquals(1, InstBinaryTree.recursiveCalls)
}
@Test
fun testPreorder() {
assertEquals(emptyList<String>(), tree.preorderKeys())
assertEquals(1, InstBinaryTree.recursiveCalls)
}
@Test
fun testPostorder() {
assertEquals(emptyList<String>(), tree.postorderKeys())
assertEquals(1, InstBinaryTree.recursiveCalls)
}
@Test
fun testLargeur() {
assertEquals(emptyList<String>(), tree.breadthOrderKeys())
assertEquals(1, InstBinaryTree.recursiveCalls)
}
@Test
fun testString() {
println(tree)
assertEquals(1, InstBinaryTree.recursiveCalls)
assertEquals("_", tree.toString())
assertEquals(2, InstBinaryTree.recursiveCalls)
}
}
\ No newline at end of file
import but3.collections.BinaryTree
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
class Test2ArbreFeuille {
companion object {
var leaf: BinaryTree<Int> = InstBinaryTree(10)
}
@BeforeEach
fun init() {
InstBinaryTree.reinit()
}
@Test
fun testnonvide() {
assertFalse(leaf.isEmpty())
assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testtaille() {
assertEquals(1, leaf.size())
assertEquals(1, InstBinaryTree.recursiveCalls)
}
@Test
fun testhauteur() {
assertEquals(0, leaf.height())
assertEquals(1, InstBinaryTree.recursiveCalls)
}
@Test
fun testnbfeuilles() {
assertEquals(1, leaf.nbLeafs())
assertEquals(1, InstBinaryTree.recursiveCalls)
}
@Test
fun testinorder() {
assertEquals(listOf(10), leaf.inorderKeys())
assertEquals(1, InstBinaryTree.recursiveCalls)
}
@Test
fun testpreorder() {
assertEquals(listOf(10), leaf.preorderKeys())
assertEquals(1, InstBinaryTree.recursiveCalls)
}
@Test
fun testpostorder() {
assertEquals(listOf(10), leaf.postorderKeys())
assertEquals(1, InstBinaryTree.recursiveCalls)
}
@Test
fun testlargeur() {
assertEquals(listOf(10), leaf.breadthOrderKeys())
assertEquals(3, InstBinaryTree.recursiveCalls)
}
@Test
fun testString() {
println(leaf)
assertEquals(2, InstBinaryTree.recursiveCalls)
assertEquals("└─> 10\n", leaf.toString())
assertEquals(4, InstBinaryTree.recursiveCalls)
}
}
\ No newline at end of file
import but3.collections.BinaryTree
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
class Test3ArbreSimple {
companion object {
val basicTree: BinaryTree<Int> = InstBinaryTree(
42,
InstBinaryTree(10, right = InstBinaryTree(12)),
InstBinaryTree(key = 6, left = InstBinaryTree(45))
)
}
@BeforeEach
fun init() {
InstBinaryTree.reinit()
}
@Test
fun testNonVide() {
assertFalse(basicTree.isEmpty())
assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testTaille() {
assertEquals(5, basicTree.size())
assertEquals(5, InstBinaryTree.recursiveCalls)
}
@Test
fun testHauteur() {
assertEquals(2, basicTree.height())
assertEquals(5, InstBinaryTree.recursiveCalls)
}
@Test
fun testNbFeuilles() {
assertEquals(2, basicTree.nbLeafs())
assertEquals(5, InstBinaryTree.recursiveCalls)
}
@Test
fun testInorder() {
assertEquals(listOf(10, 12, 42, 45, 6), basicTree.inorderKeys())
assertEquals(5, InstBinaryTree.recursiveCalls)
}
@Test
fun testPreorder() {
assertEquals(listOf(42, 10, 12, 6, 45), basicTree.preorderKeys())
assertEquals(5, InstBinaryTree.recursiveCalls)
}
@Test
fun testPostorder() {
assertEquals(listOf(12, 10, 45, 6, 42), basicTree.postorderKeys())
assertEquals(5, InstBinaryTree.recursiveCalls)
}
@Test
fun testLargeur() {
assertEquals(listOf(42,10,6,12,45), basicTree.breadthOrderKeys())
assertEquals(5, InstBinaryTree.recursiveCalls)
}
@Test
fun testString() {
println(basicTree)
assertEquals(6, InstBinaryTree.recursiveCalls)
assertEquals("└─> 42\n" +
" ├─> 10\n" +
" │ └─< 12\n" +
" └─< 6\n" +
" └─> 45\n", basicTree.toString())
assertEquals(12, InstBinaryTree.recursiveCalls)
}
}
\ No newline at end of file
import but3.collections.BinaryTree
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
class Test4ArbreTD {
companion object {
val parcoursInfixe = listOf("M", "H", "D", "I", "B", "J", "N", "E", "A", "F", "C", "K", "G", "O", "L")
val parcoursPrefixe = listOf("A", "B", "D", "H", "M", "I", "E", "J", "N", "C", "F", "G", "K", "L", "O")
val parcoursPostFixe = listOf("M", "H", "I", "D", "N", "J", "E", "B", "F", "K", "O", "L", "G", "C", "A")
var parcoursLargeur = listOf("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O")
val treeTD: BinaryTree<String> =
InstBinaryTree(
"A",
InstBinaryTree(
"B",
InstBinaryTree(
"D",
InstBinaryTree("H", left = InstBinaryTree("M")),
InstBinaryTree("I")
),
InstBinaryTree(
"E",
left = InstBinaryTree("J", right = InstBinaryTree("N"))
)
),
InstBinaryTree(
"C",
InstBinaryTree("F"),
InstBinaryTree(
"G",
InstBinaryTree("K"),
InstBinaryTree("L", left = InstBinaryTree("O"))
)
)
)
}
@BeforeEach
fun init() {
InstBinaryTree.reinit()
}
@Test
fun testNonVide() {
assertFalse(treeTD.isEmpty())
assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testTaille() {
assertEquals(15, treeTD.size())
assertEquals(15, InstBinaryTree.recursiveCalls)
}
@Test
fun testHauteur() {
assertEquals(4, treeTD.height())
assertEquals(15, InstBinaryTree.recursiveCalls)
}
@Test
fun testNbFeuilles() {
assertEquals(6, treeTD.nbLeafs())
assertEquals(15, InstBinaryTree.recursiveCalls)
}
@Test
fun testInorder() {
assertEquals(parcoursInfixe, treeTD.inorderKeys())
assertEquals(15, InstBinaryTree.recursiveCalls)
}
@Test
fun testPreorder() {
assertEquals(parcoursPrefixe, treeTD.preorderKeys())
assertEquals(15, InstBinaryTree.recursiveCalls)
}
@Test
fun testPostorder() {
assertEquals(parcoursPostFixe, treeTD.postorderKeys())
assertEquals(15, InstBinaryTree.recursiveCalls)
}
@Test
fun testLargeur() {
assertEquals(parcoursLargeur, treeTD.breadthOrderKeys())
assertEquals(7, InstBinaryTree.recursiveCalls)
}
@Test
fun testString() {
println(treeTD)
assertEquals(16, InstBinaryTree.recursiveCalls)
assertEquals("└─> A\n" +
" ├─> B\n" +
" │ ├─> D\n" +
" │ │ ├─> H\n" +
" │ │ │ └─> M\n" +
" │ │ └─< I\n" +
" │ └─< E\n" +
" │ └─> J\n" +
" │ └─< N\n" +
" └─< C\n" +
" ├─> F\n" +
" └─< G\n" +
" ├─> K\n" +
" └─< L\n" +
" └─> O\n", treeTD.toString())
assertEquals(32, InstBinaryTree.recursiveCalls)
}
}
\ No newline at end of file
import but3.collections.BinaryTree
import but3.collections.BinaryTreeException
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.assertThrows
class Test5ArbreException {
lateinit var tree : BinaryTree<String>
@Test
fun noExceptionSansKey() {
assertDoesNotThrow { tree = BinaryTree() }
}
@Test
fun noExceptionOnlyKey() {
assertDoesNotThrow { tree = BinaryTree("A") }
}
@Test
fun noExceptionKeyLeft() {
assertDoesNotThrow { tree = BinaryTree("A", left = BinaryTree("B")) }
}
@Test
fun noExceptionKeyRight() {
assertDoesNotThrow { tree = BinaryTree("A", right = BinaryTree("B")) }
}
@Test
fun noExceptionKeyBoth() {
assertDoesNotThrow { tree = BinaryTree("A", left = BinaryTree("B"), right = BinaryTree("B")) }
}
@Test
fun exceptionInitLeft() {
assertThrows<BinaryTreeException> {
tree = BinaryTree(left = BinaryTree("A"))
}
}
@Test
fun exceptionInitRight() {
assertThrows<BinaryTreeException> {
tree = BinaryTree(right = BinaryTree("B"))
}
}
@Test
fun exceptionInitBoth() {
assertThrows<BinaryTreeException> {
tree = BinaryTree(left = BinaryTree("A"), right = BinaryTree("B"))
}
}
@Test
fun exceptionLeftVide() {
assertThrows<BinaryTreeException> {
tree = BinaryTree("A", left = BinaryTree())
}
}
@Test
fun exceptionRightVide() {
assertThrows<BinaryTreeException> {
tree = BinaryTree("B", right = BinaryTree())
}
}
@Test
fun exceptionBothVide() {
assertThrows<BinaryTreeException> {
tree = BinaryTree("B", left = BinaryTree(), right = BinaryTree())
}
}
}
\ No newline at end of file
import Test2ArbreFeuille.Companion.leaf
import Test3ArbreSimple.Companion.basicTree
import Test4ArbreTD.Companion.parcoursInfixe
import Test4ArbreTD.Companion.parcoursLargeur
import Test4ArbreTD.Companion.parcoursPostFixe
import Test4ArbreTD.Companion.parcoursPrefixe
import Test4ArbreTD.Companion.treeTD
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
class Test6Iterators {
@BeforeEach
fun init() {
InstBinaryTree.reinit()
}
@Test
fun testIteratorInfixLeaf() {
val iteList = listOf(10).iterator()
val iteTree = leaf.infixDepthFirstIterator()
while (iteList.hasNext() && iteTree.hasNext()) {
Assertions.assertEquals(iteList.next(), iteTree.next())
}
Assertions.assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testIteratorPrefixLeaf() {
val iteList = listOf(10).iterator()
val iteTree = leaf.prefixDepthFirstIterator()
while (iteList.hasNext() && iteTree.hasNext()) {
Assertions.assertEquals(iteList.next(), iteTree.next())
}
Assertions.assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testIteratorPostfixLeaf() {
val iteList = listOf(10).iterator()
val iteTree = leaf.postfixDepthFirstIterator()
while (iteList.hasNext() && iteTree.hasNext()) {
Assertions.assertEquals(iteList.next(), iteTree.next())
}
Assertions.assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testIteratorLargeurLeaf() {
val iteList = listOf(10).iterator()
val iteTree = leaf.breadthFirstIterator()
while (iteList.hasNext() && iteTree.hasNext()) {
Assertions.assertEquals(iteList.next(), iteTree.next())
}
Assertions.assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testIteratorLeaf() {
Assertions.assertIterableEquals(listOf(10), leaf)
Assertions.assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testIteratorInfixBasic() {
val iteList = listOf(10, 12, 42, 45, 6).iterator()
val iteTree = basicTree.infixDepthFirstIterator()
while (iteList.hasNext() && iteTree.hasNext()) {
Assertions.assertEquals(iteList.next(), iteTree.next())
}
Assertions.assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testIteratorPrefixBasic() {
val iteList = listOf(42, 10, 12, 6, 45).iterator()
val iteTree = basicTree.prefixDepthFirstIterator()
while (iteList.hasNext() && iteTree.hasNext()) {
Assertions.assertEquals(iteList.next(), iteTree.next())
}
Assertions.assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testIteratorPostfixBasic() {
val iteList = listOf(12, 10, 45, 6, 42).iterator()
val iteTree = basicTree.postfixDepthFirstIterator()
while (iteList.hasNext() && iteTree.hasNext()) {
Assertions.assertEquals(iteList.next(), iteTree.next())
}
Assertions.assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testIteratorLargeurBasic() {
val iteList = listOf(42,10,6,12,45).iterator()
val iteTree = basicTree.breadthFirstIterator()
while (iteList.hasNext() && iteTree.hasNext()) {
Assertions.assertEquals(iteList.next(), iteTree.next())
}
Assertions.assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testIteratorBasic() {
Assertions.assertIterableEquals(listOf(10, 12, 42, 45, 6), basicTree)
Assertions.assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testIteratorInfixTD() {
val iteList = parcoursInfixe.iterator()
val iteTree = treeTD.infixDepthFirstIterator()
while (iteList.hasNext() && iteTree.hasNext()) {
Assertions.assertEquals(iteList.next(), iteTree.next())
}
Assertions.assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testIteratorPrefixTD() {
val iteList = parcoursPrefixe.iterator()
val iteTree = treeTD.prefixDepthFirstIterator()
while (iteList.hasNext() && iteTree.hasNext()) {
Assertions.assertEquals(iteList.next(), iteTree.next())
}
Assertions.assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testIteratorPostfixTD() {
val iteList = parcoursPostFixe.iterator()
val iteTree = treeTD.postfixDepthFirstIterator()
while (iteList.hasNext() && iteTree.hasNext()) {
Assertions.assertEquals(iteList.next(), iteTree.next())
}
Assertions.assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testIteratorLargeurTD() {
val iteList = parcoursLargeur.iterator()
val iteTree = treeTD.breadthFirstIterator()
while (iteList.hasNext() && iteTree.hasNext()) {
Assertions.assertEquals(iteList.next(), iteTree.next())
}
Assertions.assertEquals(0, InstBinaryTree.recursiveCalls)
}
@Test
fun testIteratorTD() {
Assertions.assertIterableEquals(parcoursInfixe, treeTD)
Assertions.assertEquals(0, InstBinaryTree.recursiveCalls)
}
}
\ No newline at end of file
import but3.collections.BinaryTree
class InstBinaryTree<K>(
key: K? = null,
left: BinaryTree<K>? = null,
right: BinaryTree<K>? = null) : BinaryTree<K>(key,left,right) {
companion object {
var recursiveCalls = 0
fun reinit() {
recursiveCalls = 0
}
}
override fun nbLeafs(): Int {
recursiveCalls++
return super.nbLeafs()
}
override fun size(): Int {
recursiveCalls++
return super.size()
}
override fun height(): Int {
recursiveCalls++
return super.height()
}
override fun inorderKeys(): List<K> {
recursiveCalls++
return super.inorderKeys()
}
override fun breadthOrderKeys(): List<K> {
recursiveCalls++
return super.breadthOrderKeys()
}
override fun keysPerLevels(currentLevel: List<BinaryTree<K>>): List<K> {
recursiveCalls++
return super.keysPerLevels(currentLevel)
}
override fun toString(): String {
recursiveCalls++
return super.toString()
}
override fun buildString(prefix: String, isLast: Boolean, isLeft: Boolean): String {
recursiveCalls++
return super.buildString(prefix, isLast, isLeft)
}
override fun postorderKeys(): List<K> {
recursiveCalls++
return super.postorderKeys()
}
override fun preorderKeys(): List<K> {
recursiveCalls++
return super.preorderKeys()
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter