Re #7858. Changed if logic and added unit test to UnitCell.