Syncleus / aparapi

The New Official Aparapi: a framework for executing native Java and Scala code on the GPU.
http://aparapi.com
Apache License 2.0
466 stars 59 forks source link

Constructor was used as class method #104

Closed brohisoft closed 6 years ago

brohisoft commented 6 years ago

I checked the two test classes which are ContinueTest.java and ContinueTortureTest.java, where i found the constructors were being using as class methods with @Test Annotation. After using them as constructor i found 1 Failure.

/**
 * Copyright (c) 2016 - 2018 Syncleus, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.aparapi.codegen.test;

import com.aparapi.internal.exception.ClassParseException;
import com.aparapi.internal.exception.CodeGenException;
import org.junit.Ignore;
import org.junit.Test;

public class ContinueTortureTest extends com.aparapi.codegen.CodeGenJUnitBase {
    private static final String[] expectedOpenCL = null;
    private static final Class<? extends com.aparapi.internal.exception.AparapiException> expectedException = CodeGenException.class;

    @Test
    public ContinueTortureTest() {
        test(com.aparapi.codegen.test.ContinueTorture.class, expectedException, expectedOpenCL);
    }

    @Test
    public void ContinueTortureTestWorksWithCaching() {
        test(com.aparapi.codegen.test.ContinueTorture.class, expectedException, expectedOpenCL);
    }
}

and

/**
 * Copyright (c) 2016 - 2018 Syncleus, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.aparapi.codegen.test;

import org.junit.Test;

public class ContinueTest extends com.aparapi.codegen.CodeGenJUnitBase {
    private static final String[] expectedOpenCL = {
    "typedef struct This_s{\n" +
"\n" +
" int passid;\n" +
" }This;\n" +
" int get_pass_id(This *this){\n" +
" return this->passid;\n" +
" }\n" +
"\n" +
" __kernel void run(\n" +
" int passid\n" +
" ){\n" +
" This thisStruct;\n" +
" This* this=&thisStruct;\n" +
" this->passid = passid;\n" +
" {\n" +
" char pass = 0;\n" +
" for (int i = 0; i<10; i++){\n" +
" if (i==5){\n" +
" } else {\n" +
" pass = 1;\n" +
" }\n" +
" }\n" +
" return;\n" +
" }\n" +
" }\n" +
" "};
    private static final Class<? extends com.aparapi.internal.exception.AparapiException> expectedException = null;

    @Test
    public ContinueTest() {
        test(com.aparapi.codegen.test.Continue.class, expectedException, expectedOpenCL);
    }

    @Test
    public void ContinueTestWorksWithCaching() {
        test(com.aparapi.codegen.test.Continue.class, expectedException, expectedOpenCL);
    }
}
freemo commented 6 years ago

@owsoultions you need to get the test to work as it is written (by fixing non-test code).. changing the test code to work defeats the purpose.

brohisoft commented 6 years ago

in ContinueTortureTest.java sending argument as null, why? it should also send a array or bunch of characters/Strings like ContinueTest.java... am i right:?

freemo commented 6 years ago

@owsoultions right now ContinueTortureTest.java is known to throw an exception, a CodeGenException.is produced when the code is run, indicating that the source code isnt working. We set up the test right now to pass since it is a known bug. So the reason the OpenCL variable is blank and the expectedException is set to CodeGenException is exactly the reason.

Your job is to fix it so the code no longer throws an exception and instead produces OpenCL code. You will then edit ContinueTortureTest.java by putting the correct OpenCL int he string and setting expectedException to null.

CoreRasurae commented 6 years ago

@freemo I think what @owsoultions meant to say is that JUnit doesn't like tests defined in Test class constructor method, should be instead a regular test method, i.e.: instead of public ContinueTest(), it should be public void ContinueTest().

In fact my eclipse complaints about the test names having the same name as the class constructor, to avoid such confusions.

The test methods could be instead public void ContinueTestPass() if the test is intended to complete without being rejected by the implementation or public ContinueTestFail() if test should pass only if the implementation code rejects the call due to wrong parameters or otherwise must throw an exception.

freemo commented 6 years ago

@CoreRasurae Yea thats valid, in fact id like to redo our testing infrastucture entierly. We should be using

@Test(expected...)

for example