TypeScript-Test/01 Einführung/03 Bedingungen/02 Übungen.ipynb

397 lines
14 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "0a476912-ee13-42d8-b705-b711433d149a",
"metadata": {
"editable": false,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"import { assertEquals } from \"jsr:@std/assert\";"
]
},
{
"cell_type": "markdown",
"id": "d31a7ba1-13af-40a1-bb9d-4733096cc531",
"metadata": {
"editable": false,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"# Aufgabe 01.03.1\n",
"Schreibe eine Funktion `nand`, die zwei boolesche Werte als Parameter entgegennimmt. Die Rückgabe der Funktion soll `false` sein, wenn beide Paramter `true` sind. In den anderen Fällen soll die Rückgabe `true` sein.\n",
"\n",
"D.h.:\n",
"* `nand(true, true)` soll `false` liefern\n",
"* `nand(true, false)`, `nand(false, true)` und `nand(false, false)` sollen `true` zurückgeben."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9a0582d4-9acb-4dd1-86c5-3b9d4d2bd4fb",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 1,
"id": "b0deac5e-d859-47d0-a220-80d4cdcb98d4",
"metadata": {
"collapsed": true,
"editable": false,
"jupyter": {
"outputs_hidden": true,
"source_hidden": true
},
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"01.03.1: function ... \u001b[0m\u001b[31mFAILED\u001b[0m \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n",
"01.03.1: nand(1,1) ... \u001b[0m\u001b[31mFAILED\u001b[0m \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n",
"01.03.1: nand(1,0) ... \u001b[0m\u001b[31mFAILED\u001b[0m \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n",
"01.03.1: nand(0,1) ... \u001b[0m\u001b[31mFAILED\u001b[0m \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n",
"01.03.1: nand(0,0) ... \u001b[0m\u001b[31mFAILED\u001b[0m \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n",
"\n",
"\u001b[0m\u001b[1m\u001b[37m\u001b[41m ERRORS \u001b[0m\n",
"\n",
"01.03.1: function \u001b[0m\u001b[38;5;245m=> <anonymous>:1:27\u001b[0m\n",
"\u001b[0m\u001b[1m\u001b[31merror\u001b[0m: ReferenceError: assertEquals is not defined\n",
" at \u001b[0m\u001b[36m<anonymous>\u001b[0m:\u001b[0m\u001b[33m2\u001b[0m:\u001b[0m\u001b[33m3\u001b[0m\n",
"\n",
"01.03.1: nand(1,1) \u001b[0m\u001b[38;5;245m=> <anonymous>:4:6\u001b[0m\n",
"\u001b[0m\u001b[1m\u001b[31merror\u001b[0m: ReferenceError: assertEquals is not defined\n",
" at \u001b[0m\u001b[36m<anonymous>\u001b[0m:\u001b[0m\u001b[33m5\u001b[0m:\u001b[0m\u001b[33m3\u001b[0m\n",
"\n",
"01.03.1: nand(1,0) \u001b[0m\u001b[38;5;245m=> <anonymous>:7:6\u001b[0m\n",
"\u001b[0m\u001b[1m\u001b[31merror\u001b[0m: ReferenceError: assertEquals is not defined\n",
" at \u001b[0m\u001b[36m<anonymous>\u001b[0m:\u001b[0m\u001b[33m8\u001b[0m:\u001b[0m\u001b[33m3\u001b[0m\n",
"\n",
"01.03.1: nand(0,1) \u001b[0m\u001b[38;5;245m=> <anonymous>:10:6\u001b[0m\n",
"\u001b[0m\u001b[1m\u001b[31merror\u001b[0m: ReferenceError: assertEquals is not defined\n",
" at \u001b[0m\u001b[36m<anonymous>\u001b[0m:\u001b[0m\u001b[33m11\u001b[0m:\u001b[0m\u001b[33m3\u001b[0m\n",
"\n",
"01.03.1: nand(0,0) \u001b[0m\u001b[38;5;245m=> <anonymous>:13:6\u001b[0m\n",
"\u001b[0m\u001b[1m\u001b[31merror\u001b[0m: ReferenceError: assertEquals is not defined\n",
" at \u001b[0m\u001b[36m<anonymous>\u001b[0m:\u001b[0m\u001b[33m14\u001b[0m:\u001b[0m\u001b[33m3\u001b[0m\n",
"\n",
"\u001b[0m\u001b[1m\u001b[37m\u001b[41m FAILURES \u001b[0m\n",
"\n",
"01.03.1: function \u001b[0m\u001b[38;5;245m=> <anonymous>:1:27\u001b[0m\n",
"01.03.1: nand(1,1) \u001b[0m\u001b[38;5;245m=> <anonymous>:4:6\u001b[0m\n",
"01.03.1: nand(1,0) \u001b[0m\u001b[38;5;245m=> <anonymous>:7:6\u001b[0m\n",
"01.03.1: nand(0,1) \u001b[0m\u001b[38;5;245m=> <anonymous>:10:6\u001b[0m\n",
"01.03.1: nand(0,0) \u001b[0m\u001b[38;5;245m=> <anonymous>:13:6\u001b[0m\n",
"\n",
"\u001b[0m\u001b[31mFAILED\u001b[0m | 0 passed | 5 failed \u001b[0m\u001b[38;5;245m(1ms)\u001b[0m\n"
]
}
],
"source": [
"Deno.test(\"01.03.1: function\", () => {\n",
" assertEquals(typeof nand, 'function')\n",
"})\n",
"Deno.test(\"01.03.1: nand(1,1)\", () => {\n",
" assertEquals(nand(true, true), false)\n",
"})\n",
"Deno.test(\"01.03.1: nand(1,0)\", () => {\n",
" assertEquals(nand(true, false), true)\n",
"})\n",
"Deno.test(\"01.03.1: nand(0,1)\", () => {\n",
" assertEquals(nand(false, true), true)\n",
"})\n",
"Deno.test(\"01.03.1: nand(0,0)\", () => {\n",
" assertEquals(nand(false, false), true)\n",
"})"
]
},
{
"cell_type": "markdown",
"id": "57c3c062-b29e-40dc-add0-97b5c5a999c1",
"metadata": {
"editable": false,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"# Aufgabe 01.03.2\n",
"Schreibe eine Funktion `nor`, die zwei boolesche Werte als Parameter entgegennimmt. Die Rückgabe der Funktion soll genau dann `true` sein, wenn beide Paramter `false` sind. In den anderen Fällen soll die Rückgabe `false` sein.\n",
"\n",
"D.h.:\n",
"* `nor(false, false)` soll `true` liefern\n",
"* `nor(false, true)`, `nor(true, false)` und `nor(true, true)` sollen `false` zurückgeben."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7e1929b1-033a-4b9c-ba66-f67d2b0dab89",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 2,
"id": "82ff9541-bb28-4520-9c93-57185f3ea9bf",
"metadata": {
"collapsed": true,
"editable": false,
"jupyter": {
"outputs_hidden": true,
"source_hidden": true
},
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"01.03.2: function ... \u001b[0m\u001b[31mFAILED\u001b[0m \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n",
"01.03.2: nor(1,1) ... \u001b[0m\u001b[31mFAILED\u001b[0m \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n",
"01.03.2: nor(1,0) ... \u001b[0m\u001b[31mFAILED\u001b[0m \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n",
"01.03.2: nor(0,1) ... \u001b[0m\u001b[31mFAILED\u001b[0m \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n",
"01.03.2: nor(0,0) ... \u001b[0m\u001b[31mFAILED\u001b[0m \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n",
"\n",
"\u001b[0m\u001b[1m\u001b[37m\u001b[41m ERRORS \u001b[0m\n",
"\n",
"01.03.2: function \u001b[0m\u001b[38;5;245m=> <anonymous>:1:27\u001b[0m\n",
"\u001b[0m\u001b[1m\u001b[31merror\u001b[0m: ReferenceError: assertEquals is not defined\n",
" at \u001b[0m\u001b[36m<anonymous>\u001b[0m:\u001b[0m\u001b[33m2\u001b[0m:\u001b[0m\u001b[33m3\u001b[0m\n",
"\n",
"01.03.2: nor(1,1) \u001b[0m\u001b[38;5;245m=> <anonymous>:4:6\u001b[0m\n",
"\u001b[0m\u001b[1m\u001b[31merror\u001b[0m: ReferenceError: assertEquals is not defined\n",
" at \u001b[0m\u001b[36m<anonymous>\u001b[0m:\u001b[0m\u001b[33m5\u001b[0m:\u001b[0m\u001b[33m3\u001b[0m\n",
"\n",
"01.03.2: nor(1,0) \u001b[0m\u001b[38;5;245m=> <anonymous>:7:6\u001b[0m\n",
"\u001b[0m\u001b[1m\u001b[31merror\u001b[0m: ReferenceError: assertEquals is not defined\n",
" at \u001b[0m\u001b[36m<anonymous>\u001b[0m:\u001b[0m\u001b[33m8\u001b[0m:\u001b[0m\u001b[33m3\u001b[0m\n",
"\n",
"01.03.2: nor(0,1) \u001b[0m\u001b[38;5;245m=> <anonymous>:10:6\u001b[0m\n",
"\u001b[0m\u001b[1m\u001b[31merror\u001b[0m: ReferenceError: assertEquals is not defined\n",
" at \u001b[0m\u001b[36m<anonymous>\u001b[0m:\u001b[0m\u001b[33m11\u001b[0m:\u001b[0m\u001b[33m3\u001b[0m\n",
"\n",
"01.03.2: nor(0,0) \u001b[0m\u001b[38;5;245m=> <anonymous>:13:6\u001b[0m\n",
"\u001b[0m\u001b[1m\u001b[31merror\u001b[0m: ReferenceError: assertEquals is not defined\n",
" at \u001b[0m\u001b[36m<anonymous>\u001b[0m:\u001b[0m\u001b[33m14\u001b[0m:\u001b[0m\u001b[33m3\u001b[0m\n",
"\n",
"\u001b[0m\u001b[1m\u001b[37m\u001b[41m FAILURES \u001b[0m\n",
"\n",
"01.03.2: function \u001b[0m\u001b[38;5;245m=> <anonymous>:1:27\u001b[0m\n",
"01.03.2: nor(1,1) \u001b[0m\u001b[38;5;245m=> <anonymous>:4:6\u001b[0m\n",
"01.03.2: nor(1,0) \u001b[0m\u001b[38;5;245m=> <anonymous>:7:6\u001b[0m\n",
"01.03.2: nor(0,1) \u001b[0m\u001b[38;5;245m=> <anonymous>:10:6\u001b[0m\n",
"01.03.2: nor(0,0) \u001b[0m\u001b[38;5;245m=> <anonymous>:13:6\u001b[0m\n",
"\n",
"\u001b[0m\u001b[31mFAILED\u001b[0m | 0 passed | 5 failed \u001b[0m\u001b[38;5;245m(1ms)\u001b[0m\n"
]
}
],
"source": [
"Deno.test(\"01.03.2: function\", () => {\n",
" assertEquals(typeof nor, 'function')\n",
"})\n",
"Deno.test(\"01.03.2: nor(1,1)\", () => {\n",
" assertEquals(nor(true, true), false)\n",
"})\n",
"Deno.test(\"01.03.2: nor(1,0)\", () => {\n",
" assertEquals(nor(true, false), false)\n",
"})\n",
"Deno.test(\"01.03.2: nor(0,1)\", () => {\n",
" assertEquals(nor(false, true), false)\n",
"})\n",
"Deno.test(\"01.03.2: nor(0,0)\", () => {\n",
" assertEquals(nor(false, false), true)\n",
"})"
]
},
{
"cell_type": "markdown",
"id": "340a44a5-5010-4b46-8c4c-2d7c459750eb",
"metadata": {
"editable": false,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"# Aufgabe 01.03.3\n",
"Schreibe eine Funktion `xor`, die zwei boolesche Werte als Parameter entgegennimmt. Die Rückgabe der Funktion soll `true` sein, wenn beide Paramter verschieden sind. In den anderen Fällen soll die Rückgabe `false` sein.\n",
"\n",
"D.h.:\n",
"* `xor(true, false)` und `xor(false, true)` sollen `true` liefern\n",
"* `xor(true, true)` und `xor(false, false)` sollen `false` zurückgeben."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c80d2fe9-4d8b-445a-8d1c-5803776b3d74",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d76d78ff-6a02-42d4-93bc-eb9e19be39ce",
"metadata": {
"editable": false,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"Deno.test(\"01.03.3: function\", () => {\n",
" assertEquals(typeof xor, 'function')\n",
"})\n",
"Deno.test(\"01.03.3: xor(1,1)\", () => {\n",
" assertEquals(xor(true, true), false)\n",
"})\n",
"Deno.test(\"01.03.3: xor(1,0)\", () => {\n",
" assertEquals(xor(true, false), true)\n",
"})\n",
"Deno.test(\"01.03.3: xor(0,1)\", () => {\n",
" assertEquals(xor(false, true), true)\n",
"})\n",
"Deno.test(\"01.03.3: xor(0,0)\", () => {\n",
" assertEquals(xor(false, false), false)\n",
"})"
]
},
{
"cell_type": "markdown",
"id": "e15e95e4-89e5-4cea-be8f-d95ea68eb9a7",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"# Aufgabe 01.03.4\n",
"Schreibe eine Funktion `gleich`, die zwei Werte auf strikte Gleichheit überprüft.\n",
"\n",
"Beispiel: `gleich(1, 1)` soll `true` und `gleich(1, 2)` soll `false` ergeben.\n",
"\n",
"*Hinweis: sollen bei einem Parameter unterschiedliche Datentypen übergeben werden können, so kann als Datentyp `any` genutzt werden!*"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a98dce86-57ee-41d7-bf1b-f8648430bee5",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "1af5c359-2df3-49af-82a2-0d6cc8324746",
"metadata": {
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"Deno.test(\"01.03.4: function\", () => {\n",
" assertEquals(typeof gleich, 'function')\n",
"})\n",
"Deno.test(\"01.03.4: Parameter\", () => {\n",
" assertEquals(gleich.length, 2)\n",
"})\n",
"Deno.test(\"01.03.4: gleich(1,1)\", () => {\n",
" assertEquals(gleich(1, 1), true)\n",
"})\n",
"Deno.test(\"01.03.4: gleich(1,0)\", () => {\n",
" assertEquals(gleich(1, 0), false)\n",
"})\n",
"Deno.test(\"01.03.4: gleich(1,'1')\", () => {\n",
" assertEquals(gleich(1, '1'), false)\n",
"})\n",
"Deno.test(\"01.03.4: gleich(1,2)\", () => {\n",
" assertEquals(gleich(1, 2), false)\n",
"})\n",
"Deno.test(\"01.03.4: gleich('klein','klein')\", () => {\n",
" assertEquals(gleich('klein', 'klein'), false)\n",
"})\n",
"Deno.test(\"01.03.4: gleich('Links','Rechts')\", () => {\n",
" assertEquals(gleich('Links', 'Rechts'), false)\n",
"})\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Deno",
"language": "typescript",
"name": "deno"
},
"language_info": {
"codemirror_mode": "typescript",
"file_extension": ".ts",
"mimetype": "text/x.typescript",
"name": "typescript",
"nbconvert_exporter": "script",
"pygments_lexer": "typescript",
"version": "5.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}