|
| 1 | +package com.feedzai.openml.python;/* |
| 2 | + * The copyright of this file belongs to Feedzai. The file cannot be |
| 3 | + * reproduced in whole or in part, stored in a retrieval system, |
| 4 | + * transmitted in any form, or by any means electronic, mechanical, |
| 5 | + * photocopying, or otherwise, without the prior permission of the owner. |
| 6 | + * |
| 7 | + * © 2019 Feedzai, Strictly Confidential |
| 8 | + */ |
| 9 | + |
| 10 | +import com.feedzai.openml.data.schema.DatasetSchema; |
| 11 | +import com.feedzai.openml.data.schema.FieldSchema; |
| 12 | +import com.feedzai.openml.data.schema.NumericValueSchema; |
| 13 | +import com.feedzai.openml.python.jep.instance.JepInstance; |
| 14 | +import com.google.common.collect.ImmutableList; |
| 15 | +import org.junit.Before; |
| 16 | +import org.junit.Test; |
| 17 | + |
| 18 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 19 | + |
| 20 | +/** |
| 21 | + * Tests the behaviour of a {@link ClassificationPythonModel}. |
| 22 | + * |
| 23 | + * @author Joao Sousa (joao.sousa@feedzai.com) |
| 24 | + * @since @@@feedzai.next.release@@@ |
| 25 | + */ |
| 26 | +public class ClassificationPythonModelTest { |
| 27 | + |
| 28 | + /** |
| 29 | + * A field to use in the tests. |
| 30 | + */ |
| 31 | + private static final FieldSchema FIELD_SCHEMA = |
| 32 | + new FieldSchema("field", 0, new NumericValueSchema(false)); |
| 33 | + |
| 34 | + |
| 35 | + /** |
| 36 | + * The wrapper for the Jep object used in the tests. |
| 37 | + */ |
| 38 | + private JepInstance jepInstance; |
| 39 | + |
| 40 | + /** |
| 41 | + * Initializes an instance of {@link JepInstance}. |
| 42 | + */ |
| 43 | + @Before |
| 44 | + public void setUp() { |
| 45 | + this.jepInstance = new JepInstance(); |
| 46 | + this.jepInstance.start(); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Tests that by passing a dataset schema with no target variable, will make the model creation fail. |
| 51 | + */ |
| 52 | + @Test |
| 53 | + public final void testSchemaWithoutTargetVariable() { |
| 54 | + final ImmutableList<FieldSchema> fields = ImmutableList.of(FIELD_SCHEMA); |
| 55 | + final DatasetSchema schema = new DatasetSchema(fields); |
| 56 | + |
| 57 | + assertThatThrownBy(() -> new ClassificationPythonModel(this.jepInstance, schema, "classificationModel")) |
| 58 | + .as("A classification model created with a schema with no target variable") |
| 59 | + .isInstanceOf(IllegalArgumentException.class); |
| 60 | + } |
| 61 | + |
| 62 | +} |
0 commit comments