The question the test asks
The null hypothesis H₀ assigns a probability to each category before the sample is observed. H₁ says the distribution does not follow those probabilities. For each category we calculate the expected frequency E = N × p, then add the weighted discrepancies.
χ² = Σ (O − E)² / E
When the result is valid
Observations must be independent, categories mutually exclusive and exhaustive, and every expected frequency at least 5. If a category is too small, combine it with an adjacent category before testing.
Here the theoretical probabilities are fixed independently of the data. In the Poisson example, λ = 2 is specified beforehand, not estimated from the sample. If you estimate parameters from the same data, the degrees of freedom change and this p-value calculation does not apply directly.