diff --git a/.gradle/8.10.2/executionHistory/executionHistory.bin b/.gradle/8.10.2/executionHistory/executionHistory.bin index e49f9314eff4168b11c75687f911a45a3b90620f..4ec667a2e4708051ec2ffacc5d9f2469d950538d 100644 Binary files a/.gradle/8.10.2/executionHistory/executionHistory.bin and b/.gradle/8.10.2/executionHistory/executionHistory.bin differ diff --git a/.gradle/8.10.2/executionHistory/executionHistory.lock b/.gradle/8.10.2/executionHistory/executionHistory.lock index 0310a0c904e4bbd9aff05ff9176487de03bd5f4f..f9434ab149350f0bca858c35e5aa9274e48bb691 100644 Binary files a/.gradle/8.10.2/executionHistory/executionHistory.lock and b/.gradle/8.10.2/executionHistory/executionHistory.lock differ diff --git a/.gradle/8.10.2/fileHashes/fileHashes.bin b/.gradle/8.10.2/fileHashes/fileHashes.bin index 21dbc7293c590fe99883bb7c824b834fa787f62c..5e958e6e12d60817eb19e609521b887577eaff9e 100644 Binary files a/.gradle/8.10.2/fileHashes/fileHashes.bin and b/.gradle/8.10.2/fileHashes/fileHashes.bin differ diff --git a/.gradle/8.10.2/fileHashes/fileHashes.lock b/.gradle/8.10.2/fileHashes/fileHashes.lock index a11865e8621d286625a8f307752aa185b8f1d47b..8a731737a3788deb2fae2f2bef2436f855fbd28a 100644 Binary files a/.gradle/8.10.2/fileHashes/fileHashes.lock and b/.gradle/8.10.2/fileHashes/fileHashes.lock differ diff --git a/.gradle/8.10.2/fileHashes/resourceHashesCache.bin b/.gradle/8.10.2/fileHashes/resourceHashesCache.bin index 84ba8b0733c623a6921f5ff5d85c38dcaf768918..361daef945004ae98fb8e0b135ac933f7c06db16 100644 Binary files a/.gradle/8.10.2/fileHashes/resourceHashesCache.bin and b/.gradle/8.10.2/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index e2e8f8e94e53ae45ba2a2a1af5591ef49d893ff6..5778c33693d22aa969839bc4efdaf00c873ebb97 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index a3d4a94b71e9983be62a435feb3614d4a70768dc..3f2f6054a01a1cab8e6ba3657e4863afe7d410fc 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/build/classes/java/test/model/ChargerBehaviorTest.class b/build/classes/java/test/model/ChargerBehaviorTest.class new file mode 100644 index 0000000000000000000000000000000000000000..3a2624e88a0b3dd35e00aa4cabf145835cc6084d Binary files /dev/null and b/build/classes/java/test/model/ChargerBehaviorTest.class differ diff --git a/build/classes/java/test/model/FFBoardDataTest.class b/build/classes/java/test/model/FFBoardDataTest.class new file mode 100644 index 0000000000000000000000000000000000000000..47b57cd2b4f6b676a06b9244fb0eb13aa55a4e5d Binary files /dev/null and b/build/classes/java/test/model/FFBoardDataTest.class differ diff --git a/build/classes/java/test/model/FFBoardTest.class b/build/classes/java/test/model/FFBoardTest.class new file mode 100644 index 0000000000000000000000000000000000000000..6143879ff54a9c90403c6bd1438961066dee2ae0 Binary files /dev/null and b/build/classes/java/test/model/FFBoardTest.class differ diff --git a/build/classes/java/test/model/FireFactoryTest.class b/build/classes/java/test/model/FireFactoryTest.class new file mode 100644 index 0000000000000000000000000000000000000000..dba737760e4d6456d705d17b3a3200d6f22c5994 Binary files /dev/null and b/build/classes/java/test/model/FireFactoryTest.class differ diff --git a/build/classes/java/test/model/ModelElementTest.class b/build/classes/java/test/model/ModelElementTest.class new file mode 100644 index 0000000000000000000000000000000000000000..81fd283ea06ba1b0206e2e16174b771e22bfc255 Binary files /dev/null and b/build/classes/java/test/model/ModelElementTest.class differ diff --git a/build/classes/java/test/model/TangibleBehaviorTest.class b/build/classes/java/test/model/TangibleBehaviorTest.class new file mode 100644 index 0000000000000000000000000000000000000000..c064a8e8a76ee3f904bffa20dd936ac1375d5a0e Binary files /dev/null and b/build/classes/java/test/model/TangibleBehaviorTest.class differ diff --git a/build/classes/java/test/view/FirefighterManagerGridTest.class b/build/classes/java/test/view/FirefighterManagerGridTest.class new file mode 100644 index 0000000000000000000000000000000000000000..f574728c76d8b815d23a44b2145fbf11902e5f30 Binary files /dev/null and b/build/classes/java/test/view/FirefighterManagerGridTest.class differ diff --git a/build/classes/java/test/view/ViewElementTest.class b/build/classes/java/test/view/ViewElementTest.class new file mode 100644 index 0000000000000000000000000000000000000000..54ff5bbb72700f80b2b13786b0cce2c555c54ca3 Binary files /dev/null and b/build/classes/java/test/view/ViewElementTest.class differ diff --git a/build/reports/tests/test/classes/model.ChargerBehaviorTest.html b/build/reports/tests/test/classes/model.ChargerBehaviorTest.html new file mode 100644 index 0000000000000000000000000000000000000000..1c6db6c4d42f55caf9ea10a5a62d6a94260bf1d4 --- /dev/null +++ b/build/reports/tests/test/classes/model.ChargerBehaviorTest.html @@ -0,0 +1,106 @@ +<!DOCTYPE html> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> +<meta http-equiv="x-ua-compatible" content="IE=edge"/> +<title>Test results - ChargerBehaviorTest</title> +<link href="../css/base-style.css" rel="stylesheet" type="text/css"/> +<link href="../css/style.css" rel="stylesheet" type="text/css"/> +<script src="../js/report.js" type="text/javascript"></script> +</head> +<body> +<div id="content"> +<h1>ChargerBehaviorTest</h1> +<div class="breadcrumbs"> +<a href="../index.html">all</a> > +<a href="../packages/model.html">model</a> > ChargerBehaviorTest</div> +<div id="summary"> +<table> +<tr> +<td> +<div class="summaryGroup"> +<table> +<tr> +<td> +<div class="infoBox" id="tests"> +<div class="counter">3</div> +<p>tests</p> +</div> +</td> +<td> +<div class="infoBox" id="failures"> +<div class="counter">0</div> +<p>failures</p> +</div> +</td> +<td> +<div class="infoBox" id="ignored"> +<div class="counter">0</div> +<p>ignored</p> +</div> +</td> +<td> +<div class="infoBox" id="duration"> +<div class="counter">0.100s</div> +<p>duration</p> +</div> +</td> +</tr> +</table> +</div> +</td> +<td> +<div class="infoBox success" id="successRate"> +<div class="percent">100%</div> +<p>successful</p> +</div> +</td> +</tr> +</table> +</div> +<div id="tabs"> +<ul class="tabLinks"> +<li> +<a href="#tab0">Tests</a> +</li> +</ul> +<div id="tab0" class="tab"> +<h2>Tests</h2> +<table> +<thead> +<tr> +<th>Test</th> +<th>Duration</th> +<th>Result</th> +</tr> +</thead> +<tr> +<td class="success">testChargerBehaviorForOneFire()</td> +<td class="success">0.002s</td> +<td class="success">passed</td> +</tr> +<tr> +<td class="success">testChargerBehaviorForOneQuickFire()</td> +<td class="success">0.002s</td> +<td class="success">passed</td> +</tr> +<tr> +<td class="success">testChargerBehaviorForTwoFires()</td> +<td class="success">0.096s</td> +<td class="success">passed</td> +</tr> +</table> +</div> +</div> +<div id="footer"> +<p> +<div> +<label class="hidden" id="label-for-line-wrapping-toggle" for="line-wrapping-toggle">Wrap lines +<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/> +</label> +</div>Generated by +<a href="http://www.gradle.org">Gradle 8.10.2</a> at 29 nov. 2024, 22:12:59</p> +</div> +</div> +</body> +</html> diff --git a/build/reports/tests/test/css/base-style.css b/build/reports/tests/test/css/base-style.css new file mode 100644 index 0000000000000000000000000000000000000000..4afa73e3ddcf5e21bdd0a22ac575dc99b2e3d826 --- /dev/null +++ b/build/reports/tests/test/css/base-style.css @@ -0,0 +1,179 @@ + +body { + margin: 0; + padding: 0; + font-family: sans-serif; + font-size: 12pt; +} + +body, a, a:visited { + color: #303030; +} + +#content { + padding-left: 50px; + padding-right: 50px; + padding-top: 30px; + padding-bottom: 30px; +} + +#content h1 { + font-size: 160%; + margin-bottom: 10px; +} + +#footer { + margin-top: 100px; + font-size: 80%; + white-space: nowrap; +} + +#footer, #footer a { + color: #a0a0a0; +} + +#line-wrapping-toggle { + vertical-align: middle; +} + +#label-for-line-wrapping-toggle { + vertical-align: middle; +} + +ul { + margin-left: 0; +} + +h1, h2, h3 { + white-space: nowrap; +} + +h2 { + font-size: 120%; +} + +ul.tabLinks { + padding-left: 0; + padding-top: 10px; + padding-bottom: 10px; + overflow: auto; + min-width: 800px; + width: auto !important; + width: 800px; +} + +ul.tabLinks li { + float: left; + height: 100%; + list-style: none; + padding-left: 10px; + padding-right: 10px; + padding-top: 5px; + padding-bottom: 5px; + margin-bottom: 0; + -moz-border-radius: 7px; + border-radius: 7px; + margin-right: 25px; + border: solid 1px #d4d4d4; + background-color: #f0f0f0; +} + +ul.tabLinks li:hover { + background-color: #fafafa; +} + +ul.tabLinks li.selected { + background-color: #c5f0f5; + border-color: #c5f0f5; +} + +ul.tabLinks a { + font-size: 120%; + display: block; + outline: none; + text-decoration: none; + margin: 0; + padding: 0; +} + +ul.tabLinks li h2 { + margin: 0; + padding: 0; +} + +div.tab { +} + +div.selected { + display: block; +} + +div.deselected { + display: none; +} + +div.tab table { + min-width: 350px; + width: auto !important; + width: 350px; + border-collapse: collapse; +} + +div.tab th, div.tab table { + border-bottom: solid #d0d0d0 1px; +} + +div.tab th { + text-align: left; + white-space: nowrap; + padding-left: 6em; +} + +div.tab th:first-child { + padding-left: 0; +} + +div.tab td { + white-space: nowrap; + padding-left: 6em; + padding-top: 5px; + padding-bottom: 5px; +} + +div.tab td:first-child { + padding-left: 0; +} + +div.tab td.numeric, div.tab th.numeric { + text-align: right; +} + +span.code { + display: inline-block; + margin-top: 0em; + margin-bottom: 1em; +} + +span.code pre { + font-size: 11pt; + padding-top: 10px; + padding-bottom: 10px; + padding-left: 10px; + padding-right: 10px; + margin: 0; + background-color: #f7f7f7; + border: solid 1px #d0d0d0; + min-width: 700px; + width: auto !important; + width: 700px; +} + +span.wrapped pre { + word-wrap: break-word; + white-space: pre-wrap; + word-break: break-all; +} + +label.hidden { + display: none; +} \ No newline at end of file diff --git a/build/reports/tests/test/css/style.css b/build/reports/tests/test/css/style.css new file mode 100644 index 0000000000000000000000000000000000000000..3dc4913e7a077a1f1f3810b1f20cc9275fb236bf --- /dev/null +++ b/build/reports/tests/test/css/style.css @@ -0,0 +1,84 @@ + +#summary { + margin-top: 30px; + margin-bottom: 40px; +} + +#summary table { + border-collapse: collapse; +} + +#summary td { + vertical-align: top; +} + +.breadcrumbs, .breadcrumbs a { + color: #606060; +} + +.infoBox { + width: 110px; + padding-top: 15px; + padding-bottom: 15px; + text-align: center; +} + +.infoBox p { + margin: 0; +} + +.counter, .percent { + font-size: 120%; + font-weight: bold; + margin-bottom: 8px; +} + +#duration { + width: 125px; +} + +#successRate, .summaryGroup { + border: solid 2px #d0d0d0; + -moz-border-radius: 10px; + border-radius: 10px; +} + +#successRate { + width: 140px; + margin-left: 35px; +} + +#successRate .percent { + font-size: 180%; +} + +.success, .success a { + color: #008000; +} + +div.success, #successRate.success { + background-color: #bbd9bb; + border-color: #008000; +} + +.failures, .failures a { + color: #b60808; +} + +.skipped, .skipped a { + color: #c09853; +} + +div.failures, #successRate.failures { + background-color: #ecdada; + border-color: #b60808; +} + +ul.linkList { + padding-left: 0; +} + +ul.linkList li { + list-style: none; + margin-bottom: 5px; +} diff --git a/build/reports/tests/test/index.html b/build/reports/tests/test/index.html new file mode 100644 index 0000000000000000000000000000000000000000..133fb2a67cbbd61fbbdd932c589454ea70ac00e6 --- /dev/null +++ b/build/reports/tests/test/index.html @@ -0,0 +1,133 @@ +<!DOCTYPE html> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> +<meta http-equiv="x-ua-compatible" content="IE=edge"/> +<title>Test results - Test Summary</title> +<link href="css/base-style.css" rel="stylesheet" type="text/css"/> +<link href="css/style.css" rel="stylesheet" type="text/css"/> +<script src="js/report.js" type="text/javascript"></script> +</head> +<body> +<div id="content"> +<h1>Test Summary</h1> +<div id="summary"> +<table> +<tr> +<td> +<div class="summaryGroup"> +<table> +<tr> +<td> +<div class="infoBox" id="tests"> +<div class="counter">3</div> +<p>tests</p> +</div> +</td> +<td> +<div class="infoBox" id="failures"> +<div class="counter">0</div> +<p>failures</p> +</div> +</td> +<td> +<div class="infoBox" id="ignored"> +<div class="counter">0</div> +<p>ignored</p> +</div> +</td> +<td> +<div class="infoBox" id="duration"> +<div class="counter">0.100s</div> +<p>duration</p> +</div> +</td> +</tr> +</table> +</div> +</td> +<td> +<div class="infoBox success" id="successRate"> +<div class="percent">100%</div> +<p>successful</p> +</div> +</td> +</tr> +</table> +</div> +<div id="tabs"> +<ul class="tabLinks"> +<li> +<a href="#tab0">Packages</a> +</li> +<li> +<a href="#tab1">Classes</a> +</li> +</ul> +<div id="tab0" class="tab"> +<h2>Packages</h2> +<table> +<thead> +<tr> +<th>Package</th> +<th>Tests</th> +<th>Failures</th> +<th>Ignored</th> +<th>Duration</th> +<th>Success rate</th> +</tr> +</thead> +<tbody> +<tr> +<td class="success"> +<a href="packages/model.html">model</a> +</td> +<td>3</td> +<td>0</td> +<td>0</td> +<td>0.100s</td> +<td class="success">100%</td> +</tr> +</tbody> +</table> +</div> +<div id="tab1" class="tab"> +<h2>Classes</h2> +<table> +<thead> +<tr> +<th>Class</th> +<th>Tests</th> +<th>Failures</th> +<th>Ignored</th> +<th>Duration</th> +<th>Success rate</th> +</tr> +</thead> +<tbody> +<tr> +<td class="success"> +<a href="classes/model.ChargerBehaviorTest.html">model.ChargerBehaviorTest</a> +</td> +<td>3</td> +<td>0</td> +<td>0</td> +<td>0.100s</td> +<td class="success">100%</td> +</tr> +</tbody> +</table> +</div> +</div> +<div id="footer"> +<p> +<div> +<label class="hidden" id="label-for-line-wrapping-toggle" for="line-wrapping-toggle">Wrap lines +<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/> +</label> +</div>Generated by +<a href="http://www.gradle.org">Gradle 8.10.2</a> at 29 nov. 2024, 22:12:59</p> +</div> +</div> +</body> +</html> diff --git a/build/reports/tests/test/js/report.js b/build/reports/tests/test/js/report.js new file mode 100644 index 0000000000000000000000000000000000000000..83bab4a19f36a6f460c6747ad6b7252f63a1fad3 --- /dev/null +++ b/build/reports/tests/test/js/report.js @@ -0,0 +1,194 @@ +(function (window, document) { + "use strict"; + + var tabs = {}; + + function changeElementClass(element, classValue) { + if (element.getAttribute("className")) { + element.setAttribute("className", classValue); + } else { + element.setAttribute("class", classValue); + } + } + + function getClassAttribute(element) { + if (element.getAttribute("className")) { + return element.getAttribute("className"); + } else { + return element.getAttribute("class"); + } + } + + function addClass(element, classValue) { + changeElementClass(element, getClassAttribute(element) + " " + classValue); + } + + function removeClass(element, classValue) { + changeElementClass(element, getClassAttribute(element).replace(classValue, "")); + } + + function initTabs() { + var container = document.getElementById("tabs"); + + tabs.tabs = findTabs(container); + tabs.titles = findTitles(tabs.tabs); + tabs.headers = findHeaders(container); + tabs.select = select; + tabs.deselectAll = deselectAll; + tabs.select(0); + + return true; + } + + function getCheckBox() { + return document.getElementById("line-wrapping-toggle"); + } + + function getLabelForCheckBox() { + return document.getElementById("label-for-line-wrapping-toggle"); + } + + function findCodeBlocks() { + var spans = document.getElementById("tabs").getElementsByTagName("span"); + var codeBlocks = []; + for (var i = 0; i < spans.length; ++i) { + if (spans[i].className.indexOf("code") >= 0) { + codeBlocks.push(spans[i]); + } + } + return codeBlocks; + } + + function forAllCodeBlocks(operation) { + var codeBlocks = findCodeBlocks(); + + for (var i = 0; i < codeBlocks.length; ++i) { + operation(codeBlocks[i], "wrapped"); + } + } + + function toggleLineWrapping() { + var checkBox = getCheckBox(); + + if (checkBox.checked) { + forAllCodeBlocks(addClass); + } else { + forAllCodeBlocks(removeClass); + } + } + + function initControls() { + if (findCodeBlocks().length > 0) { + var checkBox = getCheckBox(); + var label = getLabelForCheckBox(); + + checkBox.onclick = toggleLineWrapping; + checkBox.checked = false; + + removeClass(label, "hidden"); + } + } + + function switchTab() { + var id = this.id.substr(1); + + for (var i = 0; i < tabs.tabs.length; i++) { + if (tabs.tabs[i].id === id) { + tabs.select(i); + break; + } + } + + return false; + } + + function select(i) { + this.deselectAll(); + + changeElementClass(this.tabs[i], "tab selected"); + changeElementClass(this.headers[i], "selected"); + + while (this.headers[i].firstChild) { + this.headers[i].removeChild(this.headers[i].firstChild); + } + + var h2 = document.createElement("H2"); + + h2.appendChild(document.createTextNode(this.titles[i])); + this.headers[i].appendChild(h2); + } + + function deselectAll() { + for (var i = 0; i < this.tabs.length; i++) { + changeElementClass(this.tabs[i], "tab deselected"); + changeElementClass(this.headers[i], "deselected"); + + while (this.headers[i].firstChild) { + this.headers[i].removeChild(this.headers[i].firstChild); + } + + var a = document.createElement("A"); + + a.setAttribute("id", "ltab" + i); + a.setAttribute("href", "#tab" + i); + a.onclick = switchTab; + a.appendChild(document.createTextNode(this.titles[i])); + + this.headers[i].appendChild(a); + } + } + + function findTabs(container) { + return findChildElements(container, "DIV", "tab"); + } + + function findHeaders(container) { + var owner = findChildElements(container, "UL", "tabLinks"); + return findChildElements(owner[0], "LI", null); + } + + function findTitles(tabs) { + var titles = []; + + for (var i = 0; i < tabs.length; i++) { + var tab = tabs[i]; + var header = findChildElements(tab, "H2", null)[0]; + + header.parentNode.removeChild(header); + + if (header.innerText) { + titles.push(header.innerText); + } else { + titles.push(header.textContent); + } + } + + return titles; + } + + function findChildElements(container, name, targetClass) { + var elements = []; + var children = container.childNodes; + + for (var i = 0; i < children.length; i++) { + var child = children.item(i); + + if (child.nodeType === 1 && child.nodeName === name) { + if (targetClass && child.className.indexOf(targetClass) < 0) { + continue; + } + + elements.push(child); + } + } + + return elements; + } + + // Entry point. + + window.onload = function() { + initTabs(); + initControls(); + }; +} (window, window.document)); \ No newline at end of file diff --git a/build/reports/tests/test/packages/model.html b/build/reports/tests/test/packages/model.html new file mode 100644 index 0000000000000000000000000000000000000000..ed024ab17c381c4c30d37d0c6f56b0495b406927 --- /dev/null +++ b/build/reports/tests/test/packages/model.html @@ -0,0 +1,103 @@ +<!DOCTYPE html> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> +<meta http-equiv="x-ua-compatible" content="IE=edge"/> +<title>Test results - Package model</title> +<link href="../css/base-style.css" rel="stylesheet" type="text/css"/> +<link href="../css/style.css" rel="stylesheet" type="text/css"/> +<script src="../js/report.js" type="text/javascript"></script> +</head> +<body> +<div id="content"> +<h1>Package model</h1> +<div class="breadcrumbs"> +<a href="../index.html">all</a> > model</div> +<div id="summary"> +<table> +<tr> +<td> +<div class="summaryGroup"> +<table> +<tr> +<td> +<div class="infoBox" id="tests"> +<div class="counter">3</div> +<p>tests</p> +</div> +</td> +<td> +<div class="infoBox" id="failures"> +<div class="counter">0</div> +<p>failures</p> +</div> +</td> +<td> +<div class="infoBox" id="ignored"> +<div class="counter">0</div> +<p>ignored</p> +</div> +</td> +<td> +<div class="infoBox" id="duration"> +<div class="counter">0.100s</div> +<p>duration</p> +</div> +</td> +</tr> +</table> +</div> +</td> +<td> +<div class="infoBox success" id="successRate"> +<div class="percent">100%</div> +<p>successful</p> +</div> +</td> +</tr> +</table> +</div> +<div id="tabs"> +<ul class="tabLinks"> +<li> +<a href="#tab0">Classes</a> +</li> +</ul> +<div id="tab0" class="tab"> +<h2>Classes</h2> +<table> +<thead> +<tr> +<th>Class</th> +<th>Tests</th> +<th>Failures</th> +<th>Ignored</th> +<th>Duration</th> +<th>Success rate</th> +</tr> +</thead> +<tr> +<td class="success"> +<a href="../classes/model.ChargerBehaviorTest.html">ChargerBehaviorTest</a> +</td> +<td>3</td> +<td>0</td> +<td>0</td> +<td>0.100s</td> +<td class="success">100%</td> +</tr> +</table> +</div> +</div> +<div id="footer"> +<p> +<div> +<label class="hidden" id="label-for-line-wrapping-toggle" for="line-wrapping-toggle">Wrap lines +<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/> +</label> +</div>Generated by +<a href="http://www.gradle.org">Gradle 8.10.2</a> at 29 nov. 2024, 22:12:59</p> +</div> +</div> +</body> +</html> diff --git a/build/test-results/test/TEST-model.ChargerBehaviorTest.xml b/build/test-results/test/TEST-model.ChargerBehaviorTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..8d4100eae2a1d6c307248e952a69cba016e45bc5 --- /dev/null +++ b/build/test-results/test/TEST-model.ChargerBehaviorTest.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<testsuite name="model.ChargerBehaviorTest" tests="3" skipped="0" failures="0" errors="0" timestamp="2024-11-29T21:12:59" hostname="DESKTOP-ETSE1TF" time="0.102"> + <properties/> + <testcase name="testChargerBehaviorForTwoFires()" classname="model.ChargerBehaviorTest" time="0.096"/> + <testcase name="testChargerBehaviorForOneFire()" classname="model.ChargerBehaviorTest" time="0.002"/> + <testcase name="testChargerBehaviorForOneQuickFire()" classname="model.ChargerBehaviorTest" time="0.002"/> + <system-out><![CDATA[]]></system-out> + <system-err><![CDATA[]]></system-err> +</testsuite> diff --git a/build/test-results/test/binary/output.bin b/build/test-results/test/binary/output.bin new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/build/test-results/test/binary/output.bin.idx b/build/test-results/test/binary/output.bin.idx new file mode 100644 index 0000000000000000000000000000000000000000..f76dd238ade08917e6712764a16a22005a50573d Binary files /dev/null and b/build/test-results/test/binary/output.bin.idx differ diff --git a/build/tmp/compileTestJava/previous-compilation-data.bin b/build/tmp/compileTestJava/previous-compilation-data.bin new file mode 100644 index 0000000000000000000000000000000000000000..52c0a78efecb6ab22eeaa40c517c3da36a37b33c Binary files /dev/null and b/build/tmp/compileTestJava/previous-compilation-data.bin differ diff --git a/model(complex).png b/model(complex).png index 1fd03db1e03054bbda37373cc6c9eb65469ccbb4..991c3047d470a1de0e95d76d27b645abf7a823b0 100644 Binary files a/model(complex).png and b/model(complex).png differ diff --git a/model(simple).png b/model(simple).png index 6e0d807005b30fbae9480870ae2a0bafc9243369..0070eb6b6a29dc1ddb5aad0dd1f5ecdb3f4235c3 100644 Binary files a/model(simple).png and b/model(simple).png differ diff --git a/src/main/java/model/Behavior.java b/src/main/java/model/Behavior.java index fe9bf22a184cd32ec6ed411243902becd9eb4db8..89f5d15a8f157d127141d8ce075ae291d97c9aa6 100644 --- a/src/main/java/model/Behavior.java +++ b/src/main/java/model/Behavior.java @@ -4,11 +4,37 @@ import util.Position; import java.util.List; import java.util.Map; - +/** + * Interface defining the behavior of elements on a board. + * Provides methods for updating elements and determining legal neighboring positions. + */ public interface Behavior { - public List<Position> update(BoardData boardData,Element element); - public List<Position> legalNeighbors(BoardData boardData,Position position); + /** + * Update the state of an element when placed on the board. + * + * @param boardData The current state of the board. + * @param element The element to update. + * @return A list of positions representing where the new generation of elements is located. + */ + public List<Position> update(BoardData boardData, Element element); + + /** + * Get a list of neighboring positions that are legal for an element to occupy. + * + * @param boardData The current state of the board. + * @param position The current position of the element. + * @return A list of neighboring positions that are considered legal for the element. + */ + public List<Position> legalNeighbors(BoardData boardData, Position position); + /** + * Get a map of all neighboring positions on the board where movement is legal. + * Each key in the map represents a position, and the corresponding value is a list + * of legal neighboring positions for that position. + * + * @param boardData The current state of the board. + * @return A map where each key is a position, and the value is a list of legal neighboring positions. + */ public Map<Position, List<Position>> allLegalNeighbors(BoardData boardData); } \ No newline at end of file diff --git a/src/main/java/model/BoardData.java b/src/main/java/model/BoardData.java index 78f4a6b30db303618045dda3964ce83e1f487329..fd7750f3f47c852be005265ead60b3203e2593c8 100644 --- a/src/main/java/model/BoardData.java +++ b/src/main/java/model/BoardData.java @@ -6,16 +6,94 @@ import util.Position; import java.util.List; import java.util.Map; +/** + * Interface representing a generic board or grid structure. + * Provides methods to interact with the board elements, neighbors, and state. + */ public interface BoardData { + + /** + * Get all elements on the board as a 2D list. + * + * @return A list of lists representing the elements on the board. + * Each sublist corresponds to a row. + */ public List<List<Element>> getElements(); + + /** + * Get the cell at a specific position on the board. + * + * @param position The position of the cell to retrieve. + * @return The cell containing the element at the specified position. + */ public Cell<Element> getCell(Position position); + + /** + * Add an element to the board. + * + * @param element The element to add to the board. + * @return True if the element was successfully added, false otherwise. + */ public Boolean addElement(Element element); + + /** + * Remove an element from the board. + * + * @param element The element to remove from the board. + */ public void removeElement(Element element); + + /** + * Get a map of all positions on the board to their respective neighbors. + * + * @return A map where each key is a position on the board, and the value is a list of neighboring positions. + */ public Map<Position, List<Position>> getNeighbors(); + + /** + * Get the neighbors of a specific position on the board. + * + * @param position The position for which to retrieve the neighbors. + * @return A list of neighboring positions. + */ public List<Position> getNeighbor(Position position); + + /** + * Get the current step of the board. + * + * This is typically used in simulations or games to track progression. + * + * @return The current step. + */ public int getStep(); + + /** + * Set the current step of the board. + * + * @param step The step value to set. + */ public void setStep(int step); + + /** + * Initialize the board. + * + * This method prepares the board for use, potentially placing initial elements + * or resetting its state. + */ public void initialize(); + + /** + * Get the number of columns in the board. + * + * @return The number of columns. + */ public int getColumnCount(); + + /** + * Get the number of rows in the board. + * + * @return The number of rows. + */ public int getRowCount(); } + diff --git a/src/main/java/model/Element.java b/src/main/java/model/Element.java index b39cca08c8f681fc8c1c71ffd8cacee47c336e81..8ba13b52d952634a08dbef849064d2e6d88413bd 100644 --- a/src/main/java/model/Element.java +++ b/src/main/java/model/Element.java @@ -2,10 +2,32 @@ package model; import model.firefighter.ModelElement; import util.Position; - +/** + * Interface representing an element on the board. + * Provides methods for retrieving the position, type, and behavior of the element. + */ public interface Element { + + /** + * Get the position of the element on the board. + * + * @return The position of the element on the board. + */ Position getPosition(); + + /** + * Get the type of the element. + * This typically represents the classification or kind of element (e.g., a specific object or unit). + * + * @return The type of the element as a {@code ModelElement}. + */ ModelElement getType(); - Behavior getBehavior(); -} + /** + * Get the behavior of the element. + * This defines how the element interacts with the board and other elements. + * + * @return The behavior associated with the element. + */ + Behavior getBehavior(); +} \ No newline at end of file diff --git a/src/main/java/model/ElementFactory.java b/src/main/java/model/ElementFactory.java index b720cd6d8baa6e3ccc1307ebbf83780714758df0..e51521496fa80354114c3a580cfc165262525f9a 100644 --- a/src/main/java/model/ElementFactory.java +++ b/src/main/java/model/ElementFactory.java @@ -5,7 +5,18 @@ import util.Position; import java.util.List; import java.util.Map; +/** + * Factory interface for creating new elements on a board. + * Provides a method to generate elements at a specific position on the board. + */ public interface ElementFactory { - public Element getNewElement(BoardData boardData, Position position); -} + /** + * Create a new element for the board at a specific position. + * + * @param boardData The current state of the board where the new element will be placed. + * @param position The position on the board where the new element should be created. + * @return A new instance of an {@code Element} to be added to the board. + */ + public Element getNewElement(BoardData boardData, Position position); +} \ No newline at end of file diff --git a/src/main/java/model/Updater.java b/src/main/java/model/Updater.java index 4243f8b2adaebde2b98cfa9b333b62a1dc7613cd..3dfde37ab093073f38bacf0083ec35a34ac5d006 100644 --- a/src/main/java/model/Updater.java +++ b/src/main/java/model/Updater.java @@ -4,8 +4,17 @@ import util.Position; import java.util.List; +/** + * Interface for updating all elements on the board. + * Provides a method to update all elements based on the current state of the board. + */ public interface Updater { + /** + * Update all elements on the board based on the current state. + * + * @param boardData The current state of the board to use for updating elements. + * @return A list of positions where the elements have been updated or changed. + */ public List<Position> updateAll(BoardData boardData); - -} +} \ No newline at end of file diff --git a/src/main/java/model/elementTokens/Chargable.java b/src/main/java/model/elementTokens/Chargable.java index d22cd72149d311d2090c4cfab4373685ebe98dc1..f3308b35d807539a43faddc4aa7f4286c66c860d 100644 --- a/src/main/java/model/elementTokens/Chargable.java +++ b/src/main/java/model/elementTokens/Chargable.java @@ -1,8 +1,34 @@ package model.elementTokens; +/** + * Interface for elements that have a chargeable counter. + * Provides methods for managing the charge state of the element. + */ public interface Chargable { + + /** + * Get the current value of the charge counter. + * + * @return The current counter value, representing the charge level of the element. + */ public int getCounter(); + + /** + * Increment the charge counter by one. + * Typically used to increase the charge level of the element. + */ public void incrementCounter(); + + /** + * Reset the charge counter to zero. + * This method can be used to fully discharge the element. + */ public void resetCounter(); + + /** + * Check if the element is fully charged. + * + * @return {@code true} if the element is fully charged, {@code false} otherwise. + */ public boolean isCharged(); } diff --git a/src/main/java/model/elementTokens/ChargeTarget.java b/src/main/java/model/elementTokens/ChargeTarget.java index 776a10b6b95ef61c3bdb11848d14f762f344b84b..8ea4e104965b6b98fb71376cb604e9c4589b93b4 100644 --- a/src/main/java/model/elementTokens/ChargeTarget.java +++ b/src/main/java/model/elementTokens/ChargeTarget.java @@ -1,5 +1,9 @@ package model.elementTokens; +/** + * Interface for elements that can be charged, extending the {@link Chargable} interface. + * This interface marks the element as a target for charging operations. + */ public interface ChargeTarget extends Chargable { } diff --git a/src/main/java/model/elementTokens/ConnexElement.java b/src/main/java/model/elementTokens/ConnexElement.java index 4dc5a1869ce5d281d35779e07387ed5b0efaf33a..aef371aa3e1bc9053d99a9625199160983242eec 100644 --- a/src/main/java/model/elementTokens/ConnexElement.java +++ b/src/main/java/model/elementTokens/ConnexElement.java @@ -3,6 +3,19 @@ package model.elementTokens; import model.Element; import model.ElementFactory; +/** + * Interface représentant un élément du modèle qui peut être associé à une fabrique d'éléments. + * <p> + * Cette interface étend l'interface {@link Element} et ajoute la capacité de fournir une fabrique + * qui peut être utilisée pour créer de nouveaux éléments similaires à celui qui l'implémente. + * </p> + */ public interface ConnexElement extends Element { + + /** + * Récupère la fabrique associée à cet élément. + * + * @return La fabrique qui peut être utilisée pour créer de nouveaux éléments du même type. + */ public ElementFactory getFactory(); } diff --git a/src/main/java/model/elementTokens/Printable.java b/src/main/java/model/elementTokens/Printable.java index 4802d711d5bbd6c14ac0967efc78fde81ee22ea7..936de62807ee3bb3a8465db540443fc5f08933fe 100644 --- a/src/main/java/model/elementTokens/Printable.java +++ b/src/main/java/model/elementTokens/Printable.java @@ -4,6 +4,15 @@ import util.Position; import java.util.List; +/** + * Interface marquant un élément qui peut être imprimé ou affiché. + * <p> + * Cette interface sert à identifier les éléments qui ont un comportement d'affichage spécifique, + * comme les éléments qui peuvent être rendus graphiquement ou textuellement. + * Elle ne contient aucune méthode, mais son but est de marquer les éléments + * pouvant être imprimés ou affichés dans une vue. + * </p> + */ public interface Printable { } diff --git a/src/main/java/model/elementTokens/Updatable.java b/src/main/java/model/elementTokens/Updatable.java index d406deabace1e3d05d9b40ddaf42820197c7a162..83f33a04ee8a49d0449530b422e5cf27db389a00 100644 --- a/src/main/java/model/elementTokens/Updatable.java +++ b/src/main/java/model/elementTokens/Updatable.java @@ -5,6 +5,25 @@ import util.Position; import java.util.List; +/** + * Interface représentant un élément pouvant être mis à jour sur le plateau. + * <p> + * Cette interface définit la méthode nécessaire pour permettre à un élément d'être mis à jour + * à chaque étape du jeu ou à chaque cycle de simulation. L'élément met à jour son état en fonction + * des données du plateau. + * </p> + */ public interface Updatable { + + /** + * Met à jour l'état de l'élément sur le plateau. + * <p> + * Cette méthode permet à l'élément d'effectuer ses propres mises à jour en fonction des données + * du plateau de jeu. Elle est généralement appelée à chaque étape du jeu ou de la simulation. + * </p> + * + * @param boardData Les données du plateau de jeu qui sont utilisées pour la mise à jour de l'élément. + * @return Une liste des positions qui ont été modifiées par cette mise à jour. + */ public List<Position> updateSelf(BoardData boardData); } diff --git a/src/main/java/model/elementTokens/ZoneDependent.java b/src/main/java/model/elementTokens/ZoneDependent.java index b1a9283e4f033023fae5a1b590aa9f3ac7e1d4ff..c341220e5c6c2a76549c55ff5e64e0e4a654ea0e 100644 --- a/src/main/java/model/elementTokens/ZoneDependent.java +++ b/src/main/java/model/elementTokens/ZoneDependent.java @@ -6,6 +6,24 @@ import util.Position; import java.util.List; import java.util.Map; +/** + * Interface représentant un élément qui dépend d'une zone spécifique pour sa création. + * <p> + * Cette interface est utilisée pour des éléments dont la création ou le comportement + * est influencé ou lié à une zone particulière du plateau. Elle fournit un moyen d'obtenir + * une fabrique associée pour la création de nouveaux éléments dépendant de cette zone. + * </p> + */ public interface ZoneDependent { + + /** + * Récupère la fabrique associée à cet élément. + * <p> + * Cette fabrique est utilisée pour créer de nouveaux éléments en fonction de la zone + * dans laquelle l'élément actuel se trouve ou de toute autre logique spécifique à la zone. + * </p> + * + * @return La fabrique associée à cet élément. + */ public ElementFactory getFactory(); } diff --git a/src/main/java/model/firefighter/FFBoardData.java b/src/main/java/model/firefighter/FFBoardData.java index 508a9f585beef2c93bd01dcd9c7809a7586709f5..86507a442f0d60713f9bd34b96f9437811335fbc 100644 --- a/src/main/java/model/firefighter/FFBoardData.java +++ b/src/main/java/model/firefighter/FFBoardData.java @@ -7,31 +7,68 @@ import util.Position; import java.util.*; +/** + * Classe représentant les données d'un plateau de jeu dans le modèle de simulation de pompiers. + * <p> + * Cette classe gère l'état du plateau, y compris la position des éléments, les voisins d'une case, + * et les actions liées au placement et à la suppression des éléments. + * </p> + */ public class FFBoardData implements BoardData { + /** Liste des éléments répartis sur le plateau par type d'élément. */ private List<List<Element>> elementList; - private Map<Position, List<Position>> neighbors = new HashMap<Position, List<Position>>(); + + /** Carte des voisins pour chaque position sur le plateau. */ + private Map<Position, List<Position>> neighbors = new HashMap<>(); + + /** Étape actuelle du jeu. */ private int step; - public int columnCount,rowCount; + + /** Nombre de colonnes du plateau. */ + public int columnCount; + + /** Nombre de lignes du plateau. */ + public int rowCount; + + /** Liste des cellules représentant chaque position du plateau. */ private List<List<Cell<Element>>> cells; + + /** + * Constructeur de la classe {@link FFBoardData}. + * <p> + * Initialise un plateau avec le nombre spécifié de lignes et de colonnes. + * </p> + * + * @param columnCount Nombre de colonnes du plateau. + * @param rowCount Nombre de lignes du plateau. + */ public FFBoardData(int columnCount, int rowCount) { - this.columnCount=columnCount; - this.rowCount=rowCount; + this.columnCount = columnCount; + this.rowCount = rowCount; initialize(); } - public void initialize(){ - step=0; - neighbors = new HashMap<Position, List<Position>>(); + + /** + * Initialise les données du plateau : positionnement des cases, voisins, et liste d'éléments. + */ + public void initialize() { + step = 0; + neighbors = new HashMap<>(); Position[][] ps = new Position[rowCount][columnCount]; - cells=new ArrayList<>(); - for (int column = 0; column < columnCount; column++){ + cells = new ArrayList<>(); + + // Initialisation des cellules et positions + for (int column = 0; column < columnCount; column++) { cells.add(new ArrayList<>()); - for (int row = 0; row < rowCount; row++){ + for (int row = 0; row < rowCount; row++) { ps[row][column] = new Position(row, column); cells.get(column).add(new Cell<>(ps[row][column])); } } - for (int column = 0; column < columnCount; column++) + + // Initialisation des voisins pour chaque position + for (int column = 0; column < columnCount; column++) { for (int row = 0; row < rowCount; row++) { List<Position> list = new ArrayList<>(); if (row > 0) list.add(ps[row - 1][column]); @@ -40,6 +77,9 @@ public class FFBoardData implements BoardData { if (column < columnCount - 1) list.add(ps[row][column + 1]); getNeighbors().put(ps[row][column], list); } + } + + // Initialisation de la liste des éléments pour chaque type d'élément elementList = new ArrayList<>(); for (int i = 0; i < ModelElement.values().length; i++) { elementList.add(new ArrayList<>()); @@ -56,14 +96,21 @@ public class FFBoardData implements BoardData { return rowCount; } - @Override public List<List<Element>> getElements() { return elementList; } - public Cell<Element> getCell(Position position){ + + /** + * Récupère la cellule correspondant à une position donnée. + * + * @param position La position pour laquelle récupérer la cellule. + * @return La cellule correspondant à la position donnée. + */ + public Cell<Element> getCell(Position position) { return cells.get(position.column()).get(position.row()); } + @Override public int getStep() { return step; @@ -71,29 +118,54 @@ public class FFBoardData implements BoardData { @Override public void setStep(int step) { - this.step=step; + this.step = step; } + + @Override public Map<Position, List<Position>> getNeighbors() { return neighbors; } + + @Override public List<Position> getNeighbor(Position position) { return neighbors.get(position); } - public Boolean addElement(Element element){ - if(element==null){ return false;} - if (element.getBehavior()!=null) - if (element.getBehavior() instanceof TangibleBehavior<?>) - if (!((TangibleBehavior)element.getBehavior()).isLegal(this,element.getPosition())) + + /** + * Ajoute un élément au plateau à la position de l'élément. + * <p> + * Avant d'ajouter l'élément, la méthode vérifie si la position est légale en fonction du comportement de l'élément. + * Si l'élément a un comportement tangible, sa légalité est vérifiée via la méthode {@link TangibleBehavior#isLegal(BoardData, Position)}. + * </p> + * + * @param element L'élément à ajouter au plateau. + * @return {@code true} si l'élément a été ajouté avec succès, {@code false} sinon. + */ + public Boolean addElement(Element element) { + if (element == null) { + return false; + } + if (element.getBehavior() != null) { + if (element.getBehavior() instanceof TangibleBehavior<?>) { + if (!((TangibleBehavior) element.getBehavior()).isLegal(this, element.getPosition())) { return false; + } + } + } elementList.get(element.getType().ordinal()).add(element); getCell(element.getPosition()).Content.add(element); FFUpdater.modifiedPositions.add(element.getPosition()); return true; } - public void removeElement(Element element){ + + /** + * Supprime un élément du plateau. + * + * @param element L'élément à supprimer. + */ + public void removeElement(Element element) { FFUpdater.modifiedPositions.add(element.getPosition()); elementList.get(element.getType().ordinal()).remove(element); getCell(element.getPosition()).Content.remove(element); } - } diff --git a/src/main/java/model/firefighter/FFUpdater.java b/src/main/java/model/firefighter/FFUpdater.java index 80ddbd78d9b655cdec376a7b81940161482faa55..5973be3477753312d82762f77f07ec10f4c130ed 100644 --- a/src/main/java/model/firefighter/FFUpdater.java +++ b/src/main/java/model/firefighter/FFUpdater.java @@ -9,25 +9,61 @@ import util.Position; import java.util.ArrayList; import java.util.List; +/** + * Classe responsable de la mise à jour des éléments dans le modèle de simulation de lutte contre les incendies. + * Elle implémente l'interface {@link Updater} et gère une liste d'éléments {@link Updatable} pour effectuer + * des mises à jour sur le plateau de jeu. + * <p> + * Cette classe est utilisée pour coordonner les mises à jour des éléments du modèle en appelant la méthode + * {@link Updatable#updateSelf(BoardData)} sur chaque élément qui peut être mis à jour. + * </p> + */ public class FFUpdater implements Updater { - List<Updatable> updatables; - static List<Position> modifiedPositions=new ArrayList<>(); + /** Liste des éléments pouvant être mis à jour. */ + private List<Updatable> updatables; + + /** Liste des positions qui ont été modifiées durant la mise à jour. */ + static List<Position> modifiedPositions = new ArrayList<>(); + + /** + * Constructeur qui initialise la liste des éléments à mettre à jour. + */ public FFUpdater() { - updatables=new ArrayList<>(); + updatables = new ArrayList<>(); } + /** + * Prépare la liste des éléments à mettre à jour et réinitialise les positions modifiées. + * Cette méthode parcourt les éléments du modèle pour ajouter ceux qui sont de type {@link Updatable} + * à la liste {@code updatables}. Elle réinitialise également la liste des positions modifiées. + * + * @param boardData L'état actuel du plateau de jeu utilisé pour récupérer les éléments à mettre à jour. + */ public void updateSetup(BoardData boardData) { updatables.clear(); - modifiedPositions=new ArrayList<Position>(); - for (ModelElement modelElement: ModelElement.values()) { - if (modelElement.isUpdatable()) - for (Element e:boardData.getElements().get(modelElement.ordinal())) { - updatables.add((Updatable) e); + modifiedPositions = new ArrayList<>(); + + // Parcours de tous les éléments du modèle pour vérifier ceux qui sont updatables + for (ModelElement modelElement : ModelElement.values()) { + if (modelElement.isUpdatable()) { + for (Element e : boardData.getElements().get(modelElement.ordinal())) { + updatables.add((Updatable) e); + } } } } + /** + * Effectue la mise à jour de tous les éléments sur le plateau de jeu. + * <p> + * Cette méthode appelle {@link Updatable#updateSelf(BoardData)} pour chaque élément {@link Updatable}, + * puis retourne une liste des positions qui ont été modifiées durant la mise à jour. + * </p> + * + * @param boardData L'état actuel du plateau de jeu utilisé pour effectuer la mise à jour des éléments. + * @return Une liste des positions qui ont été modifiées durant la mise à jour des éléments. + */ @Override public List<Position> updateAll(BoardData boardData) { updateSetup(boardData); diff --git a/src/main/java/model/firefighter/FFboardFiller.java b/src/main/java/model/firefighter/FFboardFiller.java index 87e82be0906bcb991a0a7db0a50f0c25cfe28333..553b803c401a8a12d52d5857c2a3cf5c15a592e5 100644 --- a/src/main/java/model/firefighter/FFboardFiller.java +++ b/src/main/java/model/firefighter/FFboardFiller.java @@ -10,24 +10,75 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; +/** + * Classe responsable du remplissage du plateau de jeu avec les éléments spécifiés. + * <p> + * Cette classe gère le placement des éléments du jeu sur le plateau en fonction du nombre d'éléments à placer + * (indiqué par le tableau {@code counter}). Chaque élément est instancié à une position aléatoire parmi les + * positions disponibles. Certains éléments, comme ceux de type {@link ConnexElement}, influencent les positions + * où d'autres éléments peuvent être placés. + * </p> + */ public class FFboardFiller { - Random random=new Random(); - public void fillBoard(BoardData boardData, int[] counter){ - List<Position> positions= new ArrayList<>(List.copyOf(boardData.getNeighbors().keySet())); - for(ViewElement ve:ViewElement.values()){ - if (ve!=ViewElement.EMPTY) - while(counter[ve.ordinal()]>0) { - Element element; - Position p; - do { - p=positions.get(random.nextInt(positions.size())); - element= ve.instanciate(boardData,p); - }while (!boardData.addElement(element)); - if (element instanceof ConnexElement) { - positions.removeAll(boardData.getElements().get(element.getType().ordinal()).stream().map(x ->x.getPosition()).toList()); + + /** Objet pour générer des positions aléatoires. */ + private Random random = new Random(); + + /** + * Remplie le plateau de jeu avec les éléments spécifiés dans {@code counter}. + * <p> + * Cette méthode parcourt les éléments définis dans {@link ViewElement}, instancie chaque élément à une position + * aléatoire parmi les positions disponibles sur le plateau, et les place sur le plateau en utilisant la méthode + * {@link BoardData#addElement(Element)}. + * </p> + * <p> + * Le tableau {@code counter} spécifie le nombre d'éléments de chaque type à placer. Après chaque placement, + * le compteur correspondant est décrémenté. + * </p> + * + * @param boardData L'état actuel du plateau de jeu utilisé pour ajouter les éléments. + * @param counter Tableau représentant le nombre d'éléments à placer pour chaque type d'élément (indexé par {@link ViewElement#ordinal()} ou : + * //roads + * //forests + * //rocks + * //mountains + * //firefighter + * //motorized firefighter + * //motorized firefighter (AKA superman) + * //clouds + * //fires + */ + public void fillBoard(BoardData boardData, int[] counter) { + List<Position> positions = new ArrayList<>(List.copyOf(boardData.getNeighbors().keySet())); + + // Parcours de chaque élément possible dans l'énumération ViewElement + for (ViewElement ve : ViewElement.values()) { + // On ne place pas d'élément de type EMPTY + if (ve != ViewElement.EMPTY) { + // Tant qu'il y a des éléments à placer pour ce type + while (counter[ve.ordinal()] > 0) { + Element element; + Position p; + do { + // Choisit une position aléatoire parmi les positions disponibles + p = positions.get(random.nextInt(positions.size())); + // Crée l'élément correspondant à la position choisie + element = ve.instanciate(boardData, p); + } while (!boardData.addElement(element)); // Réessaye si la position est invalide + + // Si l'élément est un ConnexElement, retire les positions occupées par ses voisins + if (element instanceof ConnexElement) { + positions.removeAll(boardData.getElements().get(element.getType().ordinal()).stream() + .map(x -> x.getPosition()) + .toList()); + } + + // Retire la position utilisée + positions.remove(p); + + // Décrémente le compteur pour ce type d'élément + counter[ve.ordinal()]--; } - positions.remove(p); - counter[ve.ordinal()]--; } } } diff --git a/src/main/java/model/firefighter/ModelElement.java b/src/main/java/model/firefighter/ModelElement.java index a9bf9649b3deed8070436444cfbddadbccf6867f..9bf376fb580967b7b6f4acecef27259a20559d5f 100644 --- a/src/main/java/model/firefighter/ModelElement.java +++ b/src/main/java/model/firefighter/ModelElement.java @@ -9,59 +9,118 @@ import util.Position; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; + +/** + * Enumération représentant les différents types d'éléments du modèle dans un jeu de lutte contre les incendies. + * Chaque valeur de l'énumération correspond à un type d'élément spécifique du jeu, comme un feu, un pompier, + * une forêt, ou une montagne. L'énumération contient des méthodes pour vérifier si un élément est imprimable ou + * mise à jour, ainsi qu'une méthode pour instancier l'élément correspondant à partir de sa position. + */ public enum ModelElement { + + /** Représente un feu standard. */ FIRE(StandardFire.class), + + /** Représente un feu rapide. */ SLOWFIRE(QuickFire.class), + + /** Représente un pompier standard. */ FIREFIGHTER(StandardFireFighter.class), + + /** Représente un pompier motorisé. */ MOTORIZEDFIREFIGHTER(MotorizedFireFighter.class), + + /** Représente un pompier industriel. */ INDUSTRIALFIREFIGHTER(IndustrialFireFighter.class), + + /** Représente un nuage. */ CLOUD(Cloud.class), + + /** Représente une montagne. */ MOUNTAIN(Mountain.class), + + /** Représente une route. */ ROAD(Road.class), + + /** Représente une forêt. */ FOREST(Forest.class), - ROCK(Rock.class); + /** Représente un rocher. */ + ROCK(Rock.class); + /** La classe associée à l'élément du modèle. */ public final Class<?> c; - ModelElement(Class<?>c) { - this.c =c; + + /** + * Constructeur pour associer une classe spécifique à chaque type d'élément du modèle. + * + * @param c La classe de l'élément correspondant. + */ + ModelElement(Class<?> c) { + this.c = c; } - public boolean isUpdatable(){ - Class<?> currentClass=c; - while(!currentClass.equals(Object.class)){ - if (Arrays.asList(currentClass.getInterfaces()).contains(Updatable.class)) return true; - currentClass=currentClass.getSuperclass(); + + /** + * Vérifie si l'élément du modèle peut être mis à jour. + * + * @return {@code true} si l'élément est de type {@link Updatable}, sinon {@code false}. + */ + public boolean isUpdatable() { + Class<?> currentClass = c; + while (!currentClass.equals(Object.class)) { + if (Arrays.asList(currentClass.getInterfaces()).contains(Updatable.class)) { + return true; + } + currentClass = currentClass.getSuperclass(); } return false; } - public boolean isPrintable(){ - Class<?> currentClass=c; - while(!currentClass.equals(Object.class)){ - if (Arrays.asList(currentClass.getInterfaces()).contains(Printable.class)) return true; - currentClass=currentClass.getSuperclass(); + + /** + * Vérifie si l'élément du modèle peut être imprimé. + * + * @return {@code true} si l'élément est de type {@link Printable}, sinon {@code false}. + */ + public boolean isPrintable() { + Class<?> currentClass = c; + while (!currentClass.equals(Object.class)) { + if (Arrays.asList(currentClass.getInterfaces()).contains(Printable.class)) { + return true; + } + currentClass = currentClass.getSuperclass(); } return false; } - public boolean isInstanceOf(Class<?> classe){ - Class<?> currentClass=c; - while(!currentClass.equals(Object.class)){ - if (currentClass.equals(classe)) return true; - currentClass=currentClass.getSuperclass(); + + /** + * Vérifie si l'élément du modèle est une instance de la classe spécifiée. + * + * @param classe La classe à comparer. + * @return {@code true} si l'élément est une instance de la classe spécifiée, sinon {@code false}. + */ + public boolean isInstanceOf(Class<?> classe) { + Class<?> currentClass = c; + while (!currentClass.equals(Object.class)) { + if (currentClass.equals(classe)) { + return true; + } + currentClass = currentClass.getSuperclass(); } return false; } - public Element instanciate(Position position){ - Class<?>[] cs=new Class<?>[]{Position.class}; - Element e= null; + /** + * Instancie un nouvel élément à partir de la classe associée et de la position spécifiée. + * + * @param position La position de l'élément à instancier sur le plateau. + * @return Une nouvelle instance de l'élément correspondant à ce modèle, positionnée à l'emplacement donné. + * @throws RuntimeException Si une erreur se produit lors de la création de l'élément. + */ + public Element instanciate(Position position) { + Class<?>[] cs = new Class<?>[] { Position.class }; + Element e = null; try { e = (Element) c.getDeclaredConstructor(cs).newInstance(position); - } catch (InstantiationException ex) { - throw new RuntimeException(ex); - } catch (IllegalAccessException ex) { - throw new RuntimeException(ex); - } catch (InvocationTargetException ex) { - throw new RuntimeException(ex); - } catch (NoSuchMethodException ex) { + } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { throw new RuntimeException(ex); } return e; diff --git a/src/main/java/model/firefighter/behaviors/IndustrialFireFighterBehavior.java b/src/main/java/model/firefighter/behaviors/IndustrialFireFighterBehavior.java index 344c5e35b950f917e86bde136bcc48046de63ec0..3c295ce8785d96b3ba0307276b9272ae4fa81dfe 100644 --- a/src/main/java/model/firefighter/behaviors/IndustrialFireFighterBehavior.java +++ b/src/main/java/model/firefighter/behaviors/IndustrialFireFighterBehavior.java @@ -19,7 +19,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -public class IndustrialFireFighterBehavior extends FireFighterBehavior implements TangibleBehavior<ModelElement>, RemoverBehavior<ModelElement>, ChargerBehavior<ModelElement> { +public class IndustrialFireFighterBehavior extends FireFighterBehavior { private TargetStrategy ts=new TargetStrategy(); diff --git a/src/main/java/model/firefighter/behaviors/NormalFireFighterBehavior.java b/src/main/java/model/firefighter/behaviors/NormalFireFighterBehavior.java index c7b67502aafe72ea0857c42b49488c5958f3c451..c5b08569f04a79813e17e627b7f37694a178d18d 100644 --- a/src/main/java/model/firefighter/behaviors/NormalFireFighterBehavior.java +++ b/src/main/java/model/firefighter/behaviors/NormalFireFighterBehavior.java @@ -19,7 +19,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -public class NormalFireFighterBehavior extends FireFighterBehavior implements TangibleBehavior<ModelElement>, RemoverBehavior<ModelElement>, ChargerBehavior<ModelElement> { +public class NormalFireFighterBehavior extends FireFighterBehavior { private TargetStrategy ts=new TargetStrategy(); diff --git a/src/main/java/model/firefighter/elements/Forest.java b/src/main/java/model/firefighter/elements/Forest.java index 99b5f7f9c8fdf10962cd485c2047aaf2160dfba8..1bffe6d45318581501af9c187bec103614fb1c27 100644 --- a/src/main/java/model/firefighter/elements/Forest.java +++ b/src/main/java/model/firefighter/elements/Forest.java @@ -4,7 +4,7 @@ import model.Element; import model.firefighter.ModelElement; import util.Position; -public class Forest extends Land implements Element { +public class Forest extends Land { //explanation : while reading the subject, I thought that any FIRE that was ON a ROCK took 4 turns instead of 2 (i changed slowfire into quickfire (1 turn) and did the forest); public Forest(Position position) { super(position); diff --git a/src/main/java/model/firefighter/elements/Mountain.java b/src/main/java/model/firefighter/elements/Mountain.java index 89db0aa2fe38ba6b9a7bec5ad9a45d063ce7735e..06c5a9b9177b5bc0c11e53368ff29ecdb8c4a4a9 100644 --- a/src/main/java/model/firefighter/elements/Mountain.java +++ b/src/main/java/model/firefighter/elements/Mountain.java @@ -4,7 +4,7 @@ import model.Element; import model.firefighter.ModelElement; import util.Position; -public class Mountain extends Land implements Element { +public class Mountain extends Land { public Mountain(Position position) { super(position); type= ModelElement.MOUNTAIN; diff --git a/src/main/java/model/firefighter/elements/QuickFire.java b/src/main/java/model/firefighter/elements/QuickFire.java index 6654b2ed9cee3b0bdcca74e4c436a34a0e5887dd..c8775e710f38ba487cc71233fc8a9c19efc75fec 100644 --- a/src/main/java/model/firefighter/elements/QuickFire.java +++ b/src/main/java/model/firefighter/elements/QuickFire.java @@ -4,7 +4,7 @@ import model.elementTokens.Updatable; import model.firefighter.ModelElement; import util.Position; -public class QuickFire extends Fire implements Updatable { +public class QuickFire extends Fire { public QuickFire(Position position) { super(1, ModelElement.SLOWFIRE, position); } diff --git a/src/main/java/model/firefighter/elements/Road.java b/src/main/java/model/firefighter/elements/Road.java index df5a5fa31dd3fd7d73c0f2f2c314d1f54123e0d7..4bfa4742f8c713f3ab592bdfec003a272329a74c 100644 --- a/src/main/java/model/firefighter/elements/Road.java +++ b/src/main/java/model/firefighter/elements/Road.java @@ -7,7 +7,7 @@ import model.firefighter.ModelElement; import model.firefighter.factories.RoadFactory; import util.Position; -public class Road extends Land implements Element, ConnexElement { +public class Road extends Land implements ConnexElement { public static ElementFactory factory=new RoadFactory(); public Road(Position position) { super(position); diff --git a/src/main/java/model/genericBehavior/ChargerBehavior.java b/src/main/java/model/genericBehavior/ChargerBehavior.java index 062362c9ae9e757772d00e93684f855e3dad957d..79a6764d801b21129d470297b2129050860e976c 100644 --- a/src/main/java/model/genericBehavior/ChargerBehavior.java +++ b/src/main/java/model/genericBehavior/ChargerBehavior.java @@ -5,7 +5,27 @@ import model.elementTokens.ChargeTarget; import java.util.List; +/** + * Interface representing the behavior of an element that can charge other elements. + * This interface extends the {@link Behavior} interface and defines methods for handling + * chargeable targets and determining their charge state. + * + * @param <E> The type of element that can be charged. + */ public interface ChargerBehavior<E> extends Behavior { + + /** + * Get the list of charge targets for the current charger. + * + * @return A list of chargeable elements that this element can charge. + */ public List<E> getChargeTarget(); + + /** + * Check if the given charge target is fully charged. + * + * @param chargeTarget The charge target to check. + * @return {@code true} if the charge target is fully charged, {@code false} otherwise. + */ public Boolean isCharged(ChargeTarget chargeTarget); } diff --git a/src/main/java/model/genericBehavior/RemoverBehavior.java b/src/main/java/model/genericBehavior/RemoverBehavior.java index 557853bb804b0a946d6bcd23e8a7e1255d985839..4a4eb946b108c466abcc99a64050d16f1e17e852 100644 --- a/src/main/java/model/genericBehavior/RemoverBehavior.java +++ b/src/main/java/model/genericBehavior/RemoverBehavior.java @@ -6,7 +6,20 @@ import util.Position; import java.util.List; +/** + * Interface representing the behavior of an element that can remove or extinguish other elements. + * This interface extends the {@link Behavior} interface and defines a method for removing elements + * from the board based on their position. + * + * @param <E> The type of element that can be removed or extinguished. + */ public interface RemoverBehavior<E> extends Behavior { - public void extinguish(BoardData boardData, Position position); + /** + * Remove or extinguish the element located at the given position on the board. + * + * @param boardData The current state of the board. + * @param position The position of the element to be removed. + */ + public void extinguish(BoardData boardData, Position position); } diff --git a/src/main/java/model/genericBehavior/TangibleBehavior.java b/src/main/java/model/genericBehavior/TangibleBehavior.java index 3f859024396b6a99fb81858e33fa9d62877e394c..d7137fa63c55d3a141570c62a7abe46cfc325047 100644 --- a/src/main/java/model/genericBehavior/TangibleBehavior.java +++ b/src/main/java/model/genericBehavior/TangibleBehavior.java @@ -6,7 +6,28 @@ import util.Position; import java.util.List; +/** + * Interface representing the behavior of an element that interacts with tangible objects on the board. + * This interface extends the {@link Behavior} interface and defines methods for retrieving obstacles + * and checking the legality of a given position on the board. + * + * @param <E> The type of element that can interact with tangible objects. + */ public interface TangibleBehavior<E> extends Behavior { + + /** + * Get the list of obstacles that this element interacts with. + * + * @return A list of obstacles (elements) that can block or affect the movement of this element. + */ public List<E> getObstacles(); + + /** + * Check if the given position is legal for the element to occupy. + * + * @param boardData The current state of the board. + * @param position The position to check for legality. + * @return {@code true} if the position is legal (e.g., not blocked by obstacles), {@code false} otherwise. + */ public Boolean isLegal(BoardData boardData, Position position); } diff --git a/src/main/java/view/ViewElement.java b/src/main/java/view/ViewElement.java index dbd8012655868944a58498f4c415be68886bcc06..40dfc22649e5682a9a1441d731b8fc1d7c9cb104 100644 --- a/src/main/java/view/ViewElement.java +++ b/src/main/java/view/ViewElement.java @@ -7,50 +7,85 @@ import util.Position; import java.lang.reflect.InvocationTargetException; +/** + * Enumération représentant les éléments visibles sur le plateau de jeu. + * <p> + * Cette énumération associe une couleur et une classe d'élément (ou une fabrique d'éléments) à chaque type d'élément + * qui peut être affiché dans la vue. Elle permet de gérer la création d'éléments visibles ainsi que leurs + * représentations graphiques. + * </p> + */ public enum ViewElement { + ROAD(Color.BLACK, Road.class, Road.factory), - FOREST(Color.color(0.0,0.2,0.0), Forest.class), + FOREST(Color.color(0.0, 0.2, 0.0), Forest.class), ROCK(Color.GREEN, Rock.class), MOUNTAIN(Color.gray(0.2), Mountain.class), FIREFIGHTER(Color.LIGHTBLUE, StandardFireFighter.class), MOTORIZEDFIREFIGHTER(Color.BLUE, MotorizedFireFighter.class), INDUSTRIALFIREFIGHTER(Color.DARKBLUE, IndustrialFireFighter.class), CLOUD(Color.gray(0.8), Cloud.class), - FIRE(Color.RED, Fire.class,Fire.factory), - + FIRE(Color.RED, Fire.class, Fire.factory), EMPTY(Color.WHITE, null); + + /** La couleur associée à l'élément. */ final Color color; + + /** La classe Java de l'élément associé. */ public final Class<?> c; + + /** La fabrique d'éléments associée à l'élément (si présente). */ final ElementFactory elementFactory; + + /** + * Constructeur pour l'élément sans fabrique spécifique. + * + * @param color La couleur associée à l'élément. + * @param c La classe de l'élément. + */ ViewElement(Color color, Class<?> c) { this.color = color; this.c = c; - this.elementFactory=null; + this.elementFactory = null; } - ViewElement(Color color, Class<?> c,ElementFactory elementFactory) { + + /** + * Constructeur pour l'élément avec une fabrique spécifique. + * + * @param color La couleur associée à l'élément. + * @param c La classe de l'élément. + * @param elementFactory La fabrique utilisée pour créer des éléments. + */ + ViewElement(Color color, Class<?> c, ElementFactory elementFactory) { this.color = color; this.c = c; - this.elementFactory=elementFactory; + this.elementFactory = elementFactory; } - public Element instanciate(BoardData boardData,Position position){ + + /** + * Instancie un élément à la position spécifiée sur le plateau de jeu. + * <p> + * Si l'élément a une fabrique associée, la fabrique est utilisée pour créer l'élément. + * Sinon, la classe de l'élément est instanciée directement avec la position. + * </p> + * + * @param boardData Les données du plateau de jeu. + * @param position La position de l'élément sur le plateau. + * @return L'élément créé. + * @throws RuntimeException si une erreur se produit lors de la création de l'élément. + */ + public Element instanciate(BoardData boardData, Position position) { Element element; - Class<?>[] arg1=new Class[]{Position.class}; - if (elementFactory!=null) { - element=elementFactory.getNewElement(boardData,position); - } - else { - try { - element=(Element)this.c.getDeclaredConstructor(arg1).newInstance(position); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } + Class<?>[] arg1 = new Class[]{Position.class}; + if (elementFactory != null) { + element = elementFactory.getNewElement(boardData, position); + } else { + try { + element = (Element) this.c.getDeclaredConstructor(arg1).newInstance(position); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + throw new RuntimeException(e); } - return element; + } + return element; } } diff --git a/src/test/java/model/ChargerBehaviorTest.java b/src/test/java/model/ChargerBehaviorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..b6dc87b31cdb022817594379f2bf6786de057a0c --- /dev/null +++ b/src/test/java/model/ChargerBehaviorTest.java @@ -0,0 +1,78 @@ +package model; + +import model.elementTokens.Updatable; +import model.firefighter.FFBoardData; +import model.firefighter.ModelElement; +import model.firefighter.elements.QuickFire; +import model.firefighter.elements.Rock; +import model.firefighter.elements.StandardFire; +import org.junit.jupiter.api.Test; +import util.Position; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ChargerBehaviorTest { + @Test + void testChargerBehaviorForOneFire(){ + Position p1 = new Position(0,0); + Position p2 = new Position(0,1); + Position p3 = new Position(0,2); + BoardData b1 = new FFBoardData(2,1); + Element r= new Rock(p2); + b1.addElement(r); + Element f= new StandardFire(p1); + b1.addElement(f); + //we have a fire and a rock in a 2x1 board; + //we need 4 hits so 8 turns + for (int i = 0; i < 8; i++) { + assertThat(b1.getElements().get(f.getType().ordinal()).size()==1).isEqualTo(true); + ((Updatable)f).updateSelf(b1); + ((Updatable)r).updateSelf(b1); + } + assertThat(b1.getElements().get(f.getType().ordinal()).size()==2).isEqualTo(true); + } + @Test + void testChargerBehaviorForOneQuickFire(){ + Position p1 = new Position(0,0); + Position p2 = new Position(0,1); + Position p3 = new Position(0,2); + BoardData b1 = new FFBoardData(2,1); + Element r= new Rock(p2); + b1.addElement(r); + Element f= new QuickFire(p1); + b1.addElement(f); + //we have a fire and a rock in a 2x1 board; + //we need 4 hits so 4 turns with QuickFire + for (int i = 0; i < 4; i++) { + assertThat(b1.getElements().get(ModelElement.FIRE.ordinal()).isEmpty()).isEqualTo(true); + assertThat(b1.getElements().get(ModelElement.SLOWFIRE.ordinal()).size()==1).isEqualTo(true); + ((Updatable)f).updateSelf(b1); + ((Updatable)r).updateSelf(b1); + } + assertThat(b1.getElements().get(ModelElement.FIRE.ordinal()).size()==1).isEqualTo(true); + assertThat(b1.getElements().get(ModelElement.SLOWFIRE.ordinal()).size()==1).isEqualTo(true); + } + + @Test + void testChargerBehaviorForTwoFires(){ + Position p1 = new Position(0,0); + Position p2 = new Position(0,1); + Position p3 = new Position(0,2); + BoardData b1 = new FFBoardData(3,1); + Element f1= new StandardFire(p1); + b1.addElement(f1); + Element r= new Rock(p2); + b1.addElement(r); + Element f3= new StandardFire(p3); + b1.addElement(f3); + //we have a fire , a rock and then another fire in a 3x1 board; + //we need 4 hits so 4 turns with QuickFire + for (int i = 0; i < 4; i++) { + assertThat(b1.getElements().get(ModelElement.FIRE.ordinal()).size()==2).isEqualTo(true); + ((Updatable)f1).updateSelf(b1); + ((Updatable)f3).updateSelf(b1); + ((Updatable)r).updateSelf(b1); + } + assertThat(b1.getElements().get(ModelElement.FIRE.ordinal()).size()==3).isEqualTo(true); + } +} diff --git a/src/test/java/model/FFBoardDataTest.java b/src/test/java/model/FFBoardDataTest.java new file mode 100644 index 0000000000000000000000000000000000000000..55addb4ddba0e9caf954d84b296cc22e882629b1 --- /dev/null +++ b/src/test/java/model/FFBoardDataTest.java @@ -0,0 +1,29 @@ +package model; + +import model.firefighter.FFBoardData; +import model.firefighter.elements.StandardFire; +import org.junit.jupiter.api.Test; +import util.Position; +import view.ViewElement; + +import java.util.Random; + +import static org.assertj.core.api.Assertions.assertThat; + +public class FFBoardDataTest { + @Test + void testAddANDRemove(){ + Random r=new Random(); + Position p; + p = new Position(r.nextInt(5),r.nextInt(5)); + BoardData boardData = new FFBoardData(5,5); + Element e = new StandardFire(p); + boardData.addElement(e); + assertThat(boardData.getCell(p).Content.contains(e)).isEqualTo(true); + assertThat(boardData.getElements().get(e.getType().ordinal()).contains(e)).isEqualTo(true); + boardData.removeElement(e); + assertThat(boardData.getCell(p).Content.contains(e)).isEqualTo(false); + assertThat(boardData.getElements().get(e.getType().ordinal()).contains(e)).isEqualTo(false); + assertThat(e.getPosition()).isEqualTo(p); + } +} diff --git a/src/test/java/model/FireFactoryTest.java b/src/test/java/model/FireFactoryTest.java new file mode 100644 index 0000000000000000000000000000000000000000..454ed60d82b7ea06f5d62427d1f0dc86aef2b662 --- /dev/null +++ b/src/test/java/model/FireFactoryTest.java @@ -0,0 +1,27 @@ +package model; + +import model.firefighter.FFBoardData; +import model.firefighter.elements.*; +import org.junit.jupiter.api.Test; +import util.Position; + +import java.util.Random; + +import static org.assertj.core.api.Assertions.assertThat; + +public class FireFactoryTest { + @Test + void testFactoryReturns(){ + Position p1 = new Position(0,0); + Position p2 = new Position(0,1); + BoardData boardData = new FFBoardData(2,1); + boardData.addElement(new Forest(p2)); + Fire f1= (Fire) Fire.factory.getNewElement(boardData,p1); + Fire f2= (Fire) Fire.factory.getNewElement(boardData,p2); + boardData.addElement(f1); + boardData.addElement(f2); + assertThat(f1 instanceof StandardFire).isEqualTo(true); + assertThat(f2 instanceof QuickFire).isEqualTo(true); + + } +} diff --git a/src/test/java/model/ModelElementTest.java b/src/test/java/model/ModelElementTest.java new file mode 100644 index 0000000000000000000000000000000000000000..900bb92c23f57a13b83f3ecfe2eed619eb67e451 --- /dev/null +++ b/src/test/java/model/ModelElementTest.java @@ -0,0 +1,27 @@ +package model; + +import model.firefighter.FFBoard; +import model.firefighter.ModelElement; +import org.junit.jupiter.api.Test; +import util.Position; + +import java.util.List; +import java.util.Random; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ModelElementTest { + @Test + void testInstanciate(){ + Random r=new Random(); + Position p; + for (ModelElement me:ModelElement.values()) { + p=new Position(r.nextInt(),r.nextInt()); + Element e=me.instanciate(p); + assertThat(e.getType()).isEqualTo(me); + assertThat(e.getClass()).isEqualTo(me.c); + assertThat(e.getPosition()).isEqualTo(p); + + } + } +} diff --git a/src/test/java/model/TangibleBehaviorTest.java b/src/test/java/model/TangibleBehaviorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..bb8a512a52416237180088e6a869561dbc711f1b --- /dev/null +++ b/src/test/java/model/TangibleBehaviorTest.java @@ -0,0 +1,27 @@ +package model; + +import model.elementTokens.Updatable; +import model.firefighter.FFBoardData; +import model.firefighter.elements.*; +import org.junit.jupiter.api.Test; +import util.Position; + +import static org.assertj.core.api.Assertions.assertThat; + +public class TangibleBehaviorTest { + @Test + void testTangibleBehavior(){ + Position p1 = new Position(0,0); + Position p2 = new Position(0,1); + BoardData b1 = new FFBoardData(2,1); + b1.addElement(new Mountain(p2)); + Element f= new StandardFire(p1); + b1.addElement(f); + //we have a fire and a mountain in a 2x1 board; + assertThat(f.getBehavior().legalNeighbors(b1, f.getPosition()).isEmpty()).isEqualTo(true); + assertThat(b1.getElements().get(f.getType().ordinal()).size()==1).isEqualTo(true); + ((Updatable)f).updateSelf(b1); + ((Updatable)f).updateSelf(b1); + assertThat(b1.getElements().get(f.getType().ordinal()).size()==1).isEqualTo(true); + } +} diff --git a/src/test/java/view/ViewElementTest.java b/src/test/java/view/ViewElementTest.java new file mode 100644 index 0000000000000000000000000000000000000000..ffa0db071b32e76759d4a05c3abc1d9732cb32f8 --- /dev/null +++ b/src/test/java/view/ViewElementTest.java @@ -0,0 +1,30 @@ +package view; + +import model.BoardData; +import model.Element; +import model.firefighter.FFBoardData; +import model.firefighter.ModelElement; +import org.junit.jupiter.api.Test; +import util.Position; +import view.ViewElement; + +import java.util.Random; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ViewElementTest { + @Test + void testInstanciate(){ + Random r=new Random(); + Position p; + for (ViewElement ve:ViewElement.values()) { + if (ve!=ViewElement.EMPTY) { + p = new Position(0, ve.ordinal()); + BoardData boardData = new FFBoardData(ViewElement.values().length, 1); + Element e = ve.instanciate(boardData, p); + assertThat(e.getType().isInstanceOf(ve.c)).isEqualTo(true); + assertThat(e.getPosition()).isEqualTo(p); + } + } + } +}