From 02e998af2dd7004a1e0a302492ac6a45b72916dd Mon Sep 17 00:00:00 2001 From: Kees van Kempen Date: Tue, 15 Mar 2022 14:18:44 +0100 Subject: [PATCH] 10: Implement unit test for task 2: done --- Week 6/10 Hyperbolic PDEs.ipynb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Week 6/10 Hyperbolic PDEs.ipynb b/Week 6/10 Hyperbolic PDEs.ipynb index 16ba3d4..f0134e3 100644 --- a/Week 6/10 Hyperbolic PDEs.ipynb +++ b/Week 6/10 Hyperbolic PDEs.ipynb @@ -320,7 +320,7 @@ "# There is an 𝑙 in the boundary conditions we assume should be a 1.\n", "a = 1\n", "l = 1\n", - "x = np.linspace(0, 1, 1200)\n", + "x = np.linspace(0, l, 1200)\n", "t = np.linspace(0, 1, 1200)\n", "f = lambda x: np.sin(2*np.pi*x)\n", "g = lambda x: 2*np.pi*np.sin(2*np.pi*x)\n", @@ -369,7 +369,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "deletable": false, "nbgrader": { @@ -387,8 +387,19 @@ "outputs": [], "source": [ "def test_pdeHyperbolic():\n", - " # YOUR CODE HERE\n", - " raise NotImplementedError()\n", + " a = 1\n", + " l = 1\n", + " x = np.linspace(0, l, 1200)\n", + " t = np.linspace(0, 1, 1200)\n", + " f = lambda x: np.sin(2*np.pi*x)\n", + " g = lambda x: 2*np.pi*np.sin(2*np.pi*x)\n", + "\n", + " w = pdeHyperbolic(a, x, t, f, g)\n", + " u = lambda x, t: np.sin(2*np.pi*x)*(np.cos(2*np.pi*t) + np.sin(2*np.pi*t))\n", + " grid = np.meshgrid(x, t)\n", + "\n", + " TOL = 1e-5\n", + " assert np.all(np.abs(u(*grid) - w) < TOL)\n", " \n", "test_pdeHyperbolic()" ]