Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
implemented tests for Quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
haeussma committed Feb 16, 2024
1 parent 1217ad2 commit 49244df
Show file tree
Hide file tree
Showing 3 changed files with 512 additions and 15 deletions.
151 changes: 136 additions & 15 deletions sdRDM/base/datatypes/test_quantity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 49,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 50,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -28,10 +28,10 @@
"output_type": "stream",
"text": [
"\u001b[4mUnitStuff\u001b[0m\n",
"├── \u001b[94mid\u001b[0m = 1b363563-32df-41b2-a4ae-4335cb0f9f6a\n",
"├── \u001b[94mid\u001b[0m = 8fa1134e-a6e4-41fe-8442-022cdee6e6f2\n",
"└── \u001b[94monly_unit\u001b[0m\n",
" └── \u001b[4mUnit\u001b[0m\n",
" ├── \u001b[94mid\u001b[0m = c996f871-1563-4f3e-a32a-ff01669bf504\n",
" ├── \u001b[94mid\u001b[0m = 8434a947-65a6-4b23-bdb5-7fda5656051e\n",
" ├── \u001b[94mname\u001b[0m = mmol / l\n",
" └── \u001b[94mbases\u001b[0m\n",
" ├── 0\n",
Expand All @@ -55,7 +55,7 @@
},
{
"cell_type": "code",
"execution_count": 102,
"execution_count": 52,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -66,7 +66,7 @@
},
{
"cell_type": "code",
"execution_count": 103,
"execution_count": 53,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -76,16 +76,16 @@
},
{
"cell_type": "code",
"execution_count": 118,
"execution_count": 54,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Quantity(id='e3f7c36b-0e73-43af-9f98-f3f36749bca4', value=0.5, unit=Unit(id='8914dfab-52ef-48aa-9abc-a9bf520f8035', name='mmol / l', bases=[BaseUnit(scale=0.001, kind=Unit(\"mol\"), exponent=1.0), BaseUnit(scale=1.0, kind=Unit(\"l\"), exponent=-1.0)]))"
"Quantity(id='a476d64d-ac25-4285-a4bc-06ed90087944', value=0.5, unit=Unit(id='2dbbfb17-98cf-41bb-85a1-eab68d4ae608', name='mmol / l', bases=[BaseUnit(scale=0.001, kind=Unit(\"mol\"), exponent=1.0), BaseUnit(scale=1.0, kind=Unit(\"l\"), exponent=-1.0)]))"
]
},
"execution_count": 118,
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -97,16 +97,16 @@
},
{
"cell_type": "code",
"execution_count": 119,
"execution_count": 55,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Quantity(id='fc034cf1-e868-4de7-85e2-4359a4d78a8e', value=4.0, unit=Unit(id='699e2af1-865b-4351-9634-a8ead9e15e22', name='l', bases=[BaseUnit(scale=1.0, kind=Unit(\"l\"), exponent=1.0)]))"
"Quantity(id='0170149a-ae7a-48a5-8cff-100c4e863497', value=4, unit=Unit(id='877589fc-26c3-4337-8e84-44fa142f3171', name='l', bases=[BaseUnit(scale=1.0, kind=Unit(\"l\"), exponent=1.0)]))"
]
},
"execution_count": 119,
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -117,23 +117,144 @@
},
{
"cell_type": "code",
"execution_count": 121,
"execution_count": 56,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Quantity(id='3dab6ffb-04e6-4131-a2d6-00ca32181d19', value=5.0, unit=Unit(id='6fda2341-d0b5-4991-a93c-d0d4850be84e', name='mmol', bases=[BaseUnit(scale=0.001, kind=Unit(\"mol\"), exponent=1.0)]))"
"Quantity(id='5ee41bd8-a9f1-4f68-80f8-211e68ea2f1d', value=5.0, unit=Unit(id='9b126978-bc26-4db3-b38d-ce73d7cdf72e', name='mmol', bases=[BaseUnit(scale=0.001, kind=Unit(\"mol\"), exponent=1.0)]))"
]
},
"execution_count": 121,
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ammount + 3"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[4mQuantity\u001b[0m\n",
"├── \u001b[94mid\u001b[0m = 36f9202f-1825-4d76-b48e-814d687bd440\n",
"├── \u001b[94mvalue\u001b[0m = 2.5\n",
"└── \u001b[94munit\u001b[0m\n",
" └── \u001b[4mUnit\u001b[0m\n",
" ├── \u001b[94mid\u001b[0m = a3f6a2a4-46d6-441e-b4be-b84aa792b8e4\n",
" ├── \u001b[94mname\u001b[0m = mmol / l\n",
" └── \u001b[94mbases\u001b[0m\n",
" ├── 0\n",
" │ └── \u001b[4mBaseUnit\u001b[0m\n",
" │ ├── \u001b[94mscale\u001b[0m = 0.001\n",
" │ ├── \u001b[94mkind\u001b[0m = mol\n",
" │ └── \u001b[94mexponent\u001b[0m = 1.0\n",
" └── 1\n",
" └── \u001b[4mBaseUnit\u001b[0m\n",
" ├── \u001b[94mscale\u001b[0m = 1.0\n",
" ├── \u001b[94mkind\u001b[0m = l\n",
" └── \u001b[94mexponent\u001b[0m = -1.0\n",
"\n"
]
}
],
"source": [
"print(conc * 5)"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\mathrm{\\frac{mmol}{\\mathcal{l}}}$"
],
"text/plain": [
"Unit(\"mmol / l\")"
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"conc.unit._unit"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 61,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Quantity(value=1, unit=\"mm\") == Quantity(value=1, unit=\"mm\")"
]
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 68,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"q1 = Quantity(value=1, unit=\"mm\")\n",
"q2 = Quantity(value=1, unit=\"mm\")\n",
"\n",
"q1.__eq__(q2) is True"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Quantity(value=1000, unit=\"mm\") == \"abx\""
]
}
],
"metadata": {
Expand Down
Empty file.
Loading

0 comments on commit 49244df

Please sign in to comment.