10: Implement unit test for task 2: done
This commit is contained in:
@ -320,7 +320,7 @@
|
|||||||
"# There is an 𝑙 in the boundary conditions we assume should be a 1.\n",
|
"# There is an 𝑙 in the boundary conditions we assume should be a 1.\n",
|
||||||
"a = 1\n",
|
"a = 1\n",
|
||||||
"l = 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",
|
"t = np.linspace(0, 1, 1200)\n",
|
||||||
"f = lambda x: np.sin(2*np.pi*x)\n",
|
"f = lambda x: np.sin(2*np.pi*x)\n",
|
||||||
"g = lambda x: 2*np.pi*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",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 4,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
@ -387,8 +387,19 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def test_pdeHyperbolic():\n",
|
"def test_pdeHyperbolic():\n",
|
||||||
" # YOUR CODE HERE\n",
|
" a = 1\n",
|
||||||
" raise NotImplementedError()\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",
|
" \n",
|
||||||
"test_pdeHyperbolic()"
|
"test_pdeHyperbolic()"
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user