From 473577102498a18235519dd788bdd23e97fe0e74 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 14 Mar 2026 16:18:42 +0000 Subject: [PATCH] Add unit tests for coherence_index function in Copy_of_Untitled7.ipynb. Co-authored-by: Sir-Ripley <31619989+Sir-Ripley@users.noreply.github.com> --- .gitignore | 1 + Copy_of_Untitled7.ipynb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ceb386 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +venv diff --git a/Copy_of_Untitled7.ipynb b/Copy_of_Untitled7.ipynb index ba82ae8..03f4ebd 100644 --- a/Copy_of_Untitled7.ipynb +++ b/Copy_of_Untitled7.ipynb @@ -222,6 +222,39 @@ "metadata": {} } ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# --- UNIT TESTS ---\n", + "import numpy as np\n", + "\n", + "def test_coherence_index():\n", + " # Test with r=0, should be 1.0\n", + " assert np.isclose(coherence_index(0, 1.5), 1.0), \"Failed on r=0\"\n", + " \n", + " # Test with typical values\n", + " r = 10\n", + " rho_info = 1.0\n", + " expected = np.exp(-10 / (10 * 1.0))\n", + " assert np.isclose(coherence_index(r, rho_info), expected), \"Failed on typical values\"\n", + " \n", + " # Test with array input\n", + " r_arr = np.array([0, 10, 20])\n", + " expected_arr = np.exp(-r_arr / (10 * 1.0))\n", + " np.testing.assert_allclose(coherence_index(r_arr, 1.0), expected_arr, err_msg=\"Failed on array input\")\n", + " \n", + " # Test error condition (e.g. division by zero if rho_info is 0)\n", + " # Although the function doesn't explicitly handle it, it will return inf or raise warning. \n", + " # We focus on the functional math values.\n", + " print(\"All tests for coherence_index passed!\")\n", + "\n", + "if __name__ == \"__main__\":\n", + " test_coherence_index()\n" + ] } ] } \ No newline at end of file