<commit_before>/// <reference path="../../../typings/globals/jasmine/index.d.ts" />
import {ConfigurationPreprocessor} from "../../../src/app/configuration/configuration-preprocessor";
import {TypeDefinition} from '../../../src/app/configuration/type-definition'
import {RelationDefinition} from '../../../src/app/configuration/relation-definition'
import {ConfigurationDefinition} from "../../../src/app/configuration/configuration-definition";

/**
 * @author <NAME>
 */
export function main() {
    describe('ConfigurationPreprocessor', () => {



        var configuration : ConfigurationDefinition;



        beforeEach(function() {

            var t : TypeDefinition =  { type: 'T1',
                fields: [
                    {
                        name: 'aField'
                    }]
            };

            configuration = {
                types : [
                    t
                ],
                relations : []
            };
        });

        function addType(configuration: ConfigurationDefinition, parent?:string) {
            var newT : TypeDefinition = {
                type: 'T'+(configuration.types.length+1),
                    fields: []
            };
            if (parent!=undefined) newT.parent = parent;
            configuration.types.push(newT);
            return configuration;
        }

        it('should add missing relations', function() {
            delete configuration.relations;
            new ConfigurationPreprocessor()
                .go(
                    configuration,
                    [],
                    [],
                    []
                );
            expect(configuration.relations.length).toBe(0);
        });

        it('should add missing type fields', function() {
            delete configuration.types[0].fields;
            new ConfigurationPreprocessor()
                .go(
                    configuration,
                    [],
                    [],
                    []
                );
            expect(configuration.types[0].fields.length).toBe(0);
        });


        it('should add extra fields', function(){

            new ConfigurationPreprocessor()
                .go(
                    configuration,
                    [],
                    [{name:'identifier'}],
                    []
                );

            expect(configuration.types[0].fields[0].name).toBe('identifier');
            expect(configuration.types[0].fields[1].name).toBe('aField');
        });
        
        
        
        it('should add extra type', function(){

            var et : TypeDefinition = { type: 'T2',
                fields: [
                    {
                        name: 'bField'
                    }]
            };

            new ConfigurationPreprocessor()
                .go(
                    configuration,
                    [et],
                    [],
                    []
                );

            expect(configuration.types[1].fields[0].name).toBe('bField');
        });


        it('should add and extra field to an extra type', function(){


            var et : TypeDefinition = { type: 'T2',
                fields: [
                    {
                        name: 'bField'
                    }]
            };

            new ConfigurationPreprocessor()
                .go(
                    configuration,
                    [et],
                    [{name:'identifier'}],
                    []
                );

            expect(configuration.types[1].fields[0].name).toBe('identifier');
            expect(configuration.types[1].fields[1].name).toBe('bField');
        });



        it('merge fields of extra type with existing type', function(){

            var et : TypeDefinition = { type: 'T1',
                fields: [
                    {
                        name: 'bField'
                    }]
            };

            new ConfigurationPreprocessor()
                .go(
                    configuration,
                    [et],
                    [],
                    []
                );

            expect(configuration.types[0].fields[0].name).toBe('aField');
            expect(configuration.types[0].fields[1].name).toBe('bField');
        });



        it('merge fields of extra type with existing type and add extra field', function(){

            var et : TypeDefinition = { type: 'T1',
                fields: [
                    {
                        name: 'bField'
                    }]
            };

            new ConfigurationPreprocessor()
                .go(
                    configuration,
                    [et],
                    [{name:'identifier'}],
                    []
                );

            expect(configuration.types[0].fields[0].name).toBe('identifier');
            expect(configuration.types[0].fields[1].name).toBe('aField');
            expect(configuration.types[0].fields[2].name).toBe('bField');
        });



        it('should not add extra fields to subtypes', function(){

            var t : TypeDefinition =  { type: 'T1',
                parent : 'SuperT',
                fields: [
                    {
                        name: 'aField'
                    }]
            };

            configuration = {
                types: [
                    t
                ],
                "relations" : []
            };

            new ConfigurationPreprocessor()
                .go(
                    configuration,
                    [],
                    [{name:'identifier'}],
                    []
                );

            expect(configuration.types[0].fields[0].name).toBe('aField');
            expect(configuration.types[0].fields[1]).toBe(undefined);
        });


        it('should add an extra relation', function() {
            var r : RelationDefinition =  { name: 'R',
                domain: [ 'domainA' ],
                range : [ 'rangeA' ]
            };
<commit_msg>Adjust test accordingly.<commit_after>/// <reference path="../../../typings/globals/jasmine/index.d.ts" />
import {ConfigurationPreprocessor} from "../../../src/app/configuration/configuration-preprocessor";
import {TypeDefinition} from '../../../src/app/configuration/type-definition'
import {RelationDefinition} from '../../../src/app/configuration/relation-definition'
import {ConfigurationDefinition} from "../../../src/app/configuration/configuration-definition";

/**
 * @author <NAME>
 */
export function main() {
    describe('ConfigurationPreprocessor', () => {



        var configuration : ConfigurationDefinition;



        beforeEach(function() {

            var t : TypeDefinition =  { type: 'T1',
                fields: [
                    {
                        name: 'aField'
                    }]
            };

            configuration = {
                types : [
                    t
                ]
            };
        });

        function addType(configuration: ConfigurationDefinition, parent?:string) {
            var newT : TypeDefinition = {
                type: 'T'+(configuration.types.length+1),
                    fields: []
            };
            if (parent!=undefined) newT.parent = parent;
            configuration.types.push(newT);
            return configuration;
        }

        it('should add missing relations', function() {
            delete configuration.relations; // in case someone defined it in before
            new ConfigurationPreprocessor()
                .go(
                    configuration,
                    [],
                    [],
                    []
                );
            expect(configuration.relations.length).toBe(0);
        });

        it('should add missing type fields', function() {
            delete configuration.types[0].fields;
            new ConfigurationPreprocessor()
                .go(
                    configuration,
                    [],
                    [],
                    []
                );
            expect(configuration.types[0].fields.length).toBe(0);
        });


        it('should add extra fields', function(){

            new ConfigurationPreprocessor()
                .go(
                    configuration,
                    [],
                    [{name:'identifier'}],
                    []
                );

            expect(configuration.types[0].fields[0].name).toBe('identifier');
            expect(configuration.types[0].fields[1].name).toBe('aField');
        });
        
        
        
        it('should add extra type', function(){

            var et : TypeDefinition = { type: 'T2',
                fields: [
                    {
                        name: 'bField'
                    }]
            };

            new ConfigurationPreprocessor()
                .go(
                    configuration,
                    [et],
                    [],
                    []
                );

            expect(configuration.types[1].fields[0].name).toBe('bField');
        });


        it('should add and extra field to an extra type', function(){


            var et : TypeDefinition = { type: 'T2',
                fields: [
                    {
                        name: 'bField'
                    }]
            };

            new ConfigurationPreprocessor()
                .go(
                    configuration,
                    [et],
                    [{name:'identifier'}],
                    []
                );

            expect(configuration.types[1].fields[0].name).toBe('identifier');
            expect(configuration.types[1].fields[1].name).toBe('bField');
        });



        it('merge fields of extra type with existing type', function(){

            var et : TypeDefinition = { type: 'T1',
                fields: [
                    {
                        name: 'bField'
                    }]
            };

            new ConfigurationPreprocessor()
                .go(
                    configuration,
                    [et],
                    [],
                    []
                );

            expect(configuration.types[0].fields[0].name).toBe('aField');
            expect(configuration.types[0].fields[1].name).toBe('bField');
        });



        it('merge fields of extra type with existing type and add extra field', function(){

            var et : TypeDefinition = { type: 'T1',
                fields: [
                    {
                        name: 'bField'
                    }]
            };

            new ConfigurationPreprocessor()
                .go(
                    configuration,
                    [et],
                    [{name:'identifier'}],
                    []
                );

            expect(configuration.types[0].fields[0].name).toBe('identifier');
            expect(configuration.types[0].fields[1].name).toBe('aField');
            expect(configuration.types[0].fields[2].name).toBe('bField');
        });



        it('should not add extra fields to subtypes', function(){

            var t : TypeDefinition =  { type: 'T1',
                parent : 'SuperT',
                fields: [
                    {
                        name: 'aField'
                    }]
            };

            configuration = {
                types: [
                    t
                ]
            };

            new ConfigurationPreprocessor()
                .go(
                    configuration,
                    [],
                    [{name:'identifier'}],
                    []
                );

            expect(configuration.types[0].fields[0].name).toBe('aField');
            expect(configuration.types[0].fields[1]).toBe(undefined);
        });


        it('should add an extra relation', function() {
            var r : RelationDefinition =  { name: 'R',
                domain: [ 'domainA' ],
                range : [ 'rangeA' ]
            };

{'fraction_non_alphanumeric': 0.12338796904900574, 'fraction_numerical': 0.005824111822947, 'mean_word_length': 1.0674234606123152, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7390410', 'n_tokens_mistral': 2808, 'n_tokens_neox': 2550, 'n_words': 483}