The theory on which a plaintiff may recover damages from a contractor for the latter's failure to construct a building in a workmanlike manner is that a party is entitled to have what was contracted for or its equivalent. If the defective work is remediable, the measure of damages is generally the cost of correcting the defect, but if the structure must be substantially rebuilt to conform to the contract, the measure of damages is generally the difference in value between what ought to have been done in the performance of the contract and what has in fact been done.