We present tests of a code designed to simulate the evolution of self-gravitating fluids in three dimensions. The code is based on the smoothed-particle hydrodynamics (SPH) technique for solving the hydrodynamical equations, together with a binary tree method for computing gravitational forces. Our tests are relevant to the evolution of non-linear structure in hierarchically clustering universes. In particular, we study the collapse and merger of quasi-spherical, slowly rotating clumps containing a mixture of gas and collisionless dark matter. For self-similar spherical collapse the detailed solution structure is already known, but we also study more realistic situations for which this is not the case. We analyse the behaviour of simulations with varying numbers of particles (N) in order to identify the minimum N for which the results are meaningful and stable. We find that the adiabatic collapse and virialization of an isolated quasi-spherical clump requires more than approximately 100 gas particles in order to avoid substantial spurious energy transfers between the gas and the dark matter. Similar numbers are needed to obtain a qualitatively correct description of the merging of clumps. With N(gas) > 300, our simulations converge to give results with only small residual systematic deviations. However, in our experiments the gas always appears to gain energy at the expense of the dark matter. This transfer has a physical rather than a numerical origin. In a collision its magnitude increases with the initial orbital energy, and it can produce significant differences in the spatial distributions of gas and dark matter in the resulting merger remnant, even if the initial distributions are identical. Finally, we test the numerical reliability of several approximate schemes for modelling additional physical processes that are likely to play a key role in the evolution of the baryonic component of galaxies, namely radiative cooling, star formation, and the injection of energy by supernovae. In particular we study how the qualitative outcome of an experiment is influenced by the detailed manner in which such modelling is carried out. Unfortunately, we find a strong sensitivity to some aspects of what can at best be a very crude representation of these processes.