test(sveta): Write tests for the web API
Outcome: done Changed: tests/test_api.py:1-96 Verified by: `make verify` — passed (compileall src/tests/app, 31 unittest tests OK) Findings: tests/test_api.py:1-96 written — 15 tests covering all 4 endpoints (add, subtract, clamp, clamp_to_byte) with success cases, missing-param failures, invalid-type failures, and boundary conditions (clamp low>high, clamp_to_byte above 255). All use Flask test client. make verify passes with 31 tests total. Open: none Confidence: high — all acceptance criteria met; each endpoint has ≥1 success test and ≥1 failure test; Flask test client used without a running server; tests follow the `# retoor` header convention in tests/; `make verify` confirmed passing. Typosaurus-Run: b3f34882127d437e93c240def12065ad Typosaurus-Node: 045e88c491a9472ea4d6e41b0ebb7d45 Typosaurus-Agent: @sveta Refs: #9
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<!-- retoor <retoor@molodetz.nl> -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Calculator</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Calculator</h1>
|
||||
|
||||
<fieldset>
|
||||
<legend>Add / Subtract</legend>
|
||||
<input type="number" id="left" placeholder="Left operand">
|
||||
<input type="number" id="right" placeholder="Right operand">
|
||||
<button onclick="calculate('add')">Add</button>
|
||||
<button onclick="calculate('subtract')">Subtract</button>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend>Clamp</legend>
|
||||
<input type="number" id="value" placeholder="Value">
|
||||
<input type="number" id="low" placeholder="Low">
|
||||
<input type="number" id="high" placeholder="High">
|
||||
<button onclick="calculate('clamp')">Clamp</button>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend>Clamp to Byte</legend>
|
||||
<input type="number" id="byte_value" placeholder="Value">
|
||||
<button onclick="calculate('clamp_to_byte')">Clamp to Byte</button>
|
||||
</fieldset>
|
||||
|
||||
<p id="output"></p>
|
||||
|
||||
<script>
|
||||
function calculate(operation) {
|
||||
const resultEl = document.getElementById('output');
|
||||
let url;
|
||||
if (operation === 'add' || operation === 'subtract') {
|
||||
const left = document.getElementById('left').value;
|
||||
const right = document.getElementById('right').value;
|
||||
url = '/' + operation + '?left=' + encodeURIComponent(left) + '&right=' + encodeURIComponent(right);
|
||||
} else if (operation === 'clamp') {
|
||||
const value = document.getElementById('value').value;
|
||||
const low = document.getElementById('low').value;
|
||||
const high = document.getElementById('high').value;
|
||||
url = '/clamp?value=' + encodeURIComponent(value) + '&low=' + encodeURIComponent(low) + '&high=' + encodeURIComponent(high);
|
||||
} else if (operation === 'clamp_to_byte') {
|
||||
const value = document.getElementById('byte_value').value;
|
||||
url = '/clamp_to_byte?value=' + encodeURIComponent(value);
|
||||
}
|
||||
fetch(url)
|
||||
.then(function(response) {
|
||||
return response.json().then(function(data) {
|
||||
if (!response.ok) {
|
||||
resultEl.textContent = 'Error: ' + (data.error || 'Unknown error');
|
||||
} else {
|
||||
resultEl.textContent = 'Result: ' + data.result;
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(function() {
|
||||
resultEl.textContent = 'Error: Network error';
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user