How optimal allocation of limited testing capacity changes epidemic dynamics