Make padSegments utility function testable and add tests