  We describe how analytic solutions for linear hydromagnetic waves can be used
for testing cosmological magnetohydrodynamic (MHD) codes. We start from the
comoving MHD equations and derive analytic solutions for the amplitude
evolution of linear hydromagnetic waves in a matter-dominated, flat
Einstein-de-Sitter (EdS) universe. The waves considered are comoving, linearly
polarized Alfv\'en waves and comoving, magnetosonic (fast) waves modified by
self-gravity. The solution for compressible waves is found for a general
adiabatic index and we consider the limits of hydrodynamics without
self-gravity in addition to the full solution. In addition to these analytic
solutions, the linearized equations are solved numerically for a $\Lambda$CDM
cosmology. We use the analytic and numeric solutions to compare with results
obtained using the cosmological MHD code AREPO and find good agreement when
using a sufficient number of grid points. We interpret the numerical damping
clearly evident in simulations with few grid points by further deriving the
Alfv\'en wave solution including physical Navier-Stokes viscosity. A comparison
between Alfv\'en wave simulations and theory reveals that the dissipation can
be described by a numerical viscosity coefficient $\eta_\mathrm{num} \propto
a^{-5/2}$ where $a$ is the scale factor. We envision that our examples could be
useful when developing a new cosmological MHD code or for regression testing of
existing codes.
