@@ -0,0 +1,2601 @@
+/*%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.facebook.presto.tpch;%0A%0Aimport com.facebook.presto.spi.statistics.Estimate;%0Aimport io.airlift.slice.Slice;%0A%0Aimport java.util.Optional;%0A%0Aimport static java.lang.String.format;%0Aimport static java.util.Optional.empty;%0Aimport static org.testng.Assert.assertEquals;%0A%0Aclass EstimateAssertion%0A%7B%0A    private final double tolerance;%0A%0A    public EstimateAssertion(double tolerance)%0A    %7B%0A        this.tolerance = tolerance;%0A    %7D%0A%0A    public void assertClose(Estimate actual, Estimate expected, String message)%0A    %7B%0A        assertClose(toOptional(actual), toOptional(expected), message);%0A    %7D%0A%0A    private Optional%3CDouble%3E toOptional(Estimate estimate)%0A    %7B%0A        return estimate.isValueUnknown() ? empty() : Optional.of(estimate.getValue());%0A    %7D%0A%0A    public void assertClose(Optional%3C?%3E actual, Optional%3C?%3E expected, String message)%0A    %7B%0A        assertEquals(actual.isPresent(), expected.isPresent(), message);%0A        if (actual.isPresent()) %7B%0A            Object actualValue = actual.get();%0A            Object expectedValue = expected.get();%0A            assertClose(actualValue, expectedValue, message);%0A        %7D%0A    %7D%0A%0A    private void assertClose(Object actual, Object expected, String message)%0A    %7B%0A        if (actual instanceof Slice) %7B%0A            assertEquals(actual.getClass(), expected.getClass(), message);%0A            assertEquals(((Slice) actual).toStringUtf8(), ((Slice) expected).toStringUtf8());%0A        %7D%0A        else %7B%0A            double actualDouble = toDouble(actual);%0A            double expectedDouble = toDouble(expected);%0A            assertEquals(actualDouble, expectedDouble, expectedDouble * tolerance, message);%0A        %7D%0A    %7D%0A%0A    private double toDouble(Object object)%0A    %7B%0A        if (object instanceof Number) %7B%0A            return ((Number) object).doubleValue();%0A        %7D%0A        else %7B%0A            String message = %22Can't compare with tolerance objects of class %25s. Use assertEquals.%22;%0A            throw new UnsupportedOperationException(format(message, object.getClass()));%0A        %7D%0A    %7D%0A%7D%0A

Add EstimateAssertion