how to work out a capacity of a battery

Charge of a battery is measured during discharge under specified conditions (often
the 10-hour rate) and after a specified full-charge cycle. The amount of charge it
takes to recharge is usually 20+% more than the capacity.

Actual practical capacities are less because you don't always start using a battery
immediately after a full charge cycle, and don't discharge uniformly at the recommended
temperature.

Measuring a discharge curve requires either a specialist battery discharge monitor
or a suitable load-resistor and regular measurements by hand - divide the voltage
values by R and integrate to get the charge.

Most battery types do not tolerate over-discharge (lithium batteries actually become
dangerous), so never discharge a battery into a dummy load unsupervised, or you'll
just trash the battery. Observe the minimum voltage and stop the discharge, immediately
recharge.