<commit_before>package tools.vitruv.dsls.commonalities.tests.execution

import static org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.Test
import static extension tools.vitruv.testutils.domains.DomainModelCreators.allElementTypes
import static extension tools.vitruv.testutils.domains.DomainModelCreators.allElementTypes2
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.^extension.ExtendWith
import org.eclipse.xtext.testing.extensions.InjectionExtension
import org.eclipse.xtext.testing.InjectWith
import tools.vitruv.dsls.commonalities.tests.CommonalitiesLanguageInjectorProvider
import org.junit.jupiter.api.TestInstance
import javax.inject.Inject
import org.junit.jupiter.api.BeforeAll
import tools.vitruv.testutils.TestProject
import java.nio.file.Path
import static tools.vitruv.testutils.metamodels.AllElementTypesCreators.aet
import static tools.vitruv.testutils.metamodels.AllElementTypes2Creators.aet2
import static tools.vitruv.testutils.matchers.ModelMatchers.contains
import static tools.vitruv.testutils.matchers.ModelMatchers.ignoringFeatures
import tools.vitruv.testutils.VitruvApplicationTest
import tools.vitruv.dsls.commonalities.tests.util.TestCommonalitiesGenerator

@ExtendWith(InjectionExtension)
@InjectWith(CommonalitiesLanguageInjectorProvider)
@TestInstance(PER_CLASS)
@DisplayName('executing a commonality with attribute mapping operators')
class AttributeMappingOperatorExecutionTest extends VitruvApplicationTest {
	@Inject TestCommonalitiesGenerator generator
	
	@BeforeAll
	def void generate(@TestProject(variant = "commonalities") Path testProject) {
		generator.generate(testProject,
			'WithAttributeMappingOperators.commonality' -> '''
				import tools.vitruv.dsls.commonalities.tests.operators.multiply
				import tools.vitruv.dsls.commonalities.tests.operators.digits
				
				import "http://tools.vitruv.testutils.metamodels.allElementTypes" as AllElementTypes
				import "http://tools.vitruv.testutils.metamodels.allElementTypes2" as AllElementTypes2
				import "http://tools.vitruv.testutils.metamodels.pcm_mockup" as PcmMockup
				import "http://tools.vitruv.testutils.metamodels.uml_mockup" as UmlMockup
				
				concept operators
				
				commonality WithAttributeMappingOperators {
				
					with AllElementTypes:(Root in Resource)
					with AllElementTypes2:(Root2 in Resource)
				
					has id {
						= AllElementTypes:Root.id
						= AllElementTypes2:Root2.id2
						-> AllElementTypes:Resource.name
						-> AllElementTypes2:Resource.name
					}
				
					has number {
						// number <-> number mapping:
						= multiply(AllElementTypes:Root.singleValuedPrimitiveTypeEAttribute, 1000)
						= AllElementTypes2:Root2.singleValuedPrimitiveTypeEAttribute2
					}
				
					has numberList {
						// number <-> numberList mapping:
						= digits(AllElementTypes:Root.singleValuedEAttribute)
						= AllElementTypes2:Root2.multiValuedEAttribute2
					}
				}
			'''
		)
	}
	
	override protected getChangePropagationSpecifications() {
		generator.createChangePropagationSpecifications()
	}

	@Test
	@DisplayName('maps a simple attribute')
	def void singleToSingleValuedAttribute() {
		resourceAt('testid'.allElementTypes).propagate [
			contents += aet.Root => [
				id = 'testid'
				singleValuedPrimitiveTypeEAttribute = 123
			]
		]

		assertThat(resourceAt('testid'.allElementTypes), contains(aet.Root => [
			id = 'testid'
			singleValuedPrimitiveTypeEAttribute = 123
		]))
		assertThat(resourceAt('testid'.allElementTypes2), contains(aet2.Root2 => [
			id2 = 'testid'
			singleValuedPrimitiveTypeEAttribute2 = 123000
		], ignoringFeatures('multiValuedEAttribute2')))
	}

	// Value is divided by 1000 and rounded towards zero
	@Test
	@DisplayName('maps a simple attribute (reverse)')
	def void singleToSingleValuedAttributeReverse() {
		resourceAt('testid'.allElementTypes2).propagate [
			contents += aet2.Root2 => [
				id2 = 'testid'
				singleValuedPrimitiveTypeEAttribute2 = 123500
			]
		]

		assertThat(resourceAt('testid'.allElementTypes2), contains(aet2.Root2 => [
			id2 = 'testid'
			singleValuedPrimitiveTypeEAttribute2 = 123500
		]))
		assertThat(resourceAt('testid'.allElementTypes), contains(aet.Root => [
			id = 'testid'
			singleValuedPrimitiveTypeEAttribute = 123
		]))
	}

	@Test<commit_msg>Adapt Commonalities tests to bidirectional execution in test domains<commit_after>package tools.vitruv.dsls.commonalities.tests.execution

import static org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.Test
import static extension tools.vitruv.testutils.domains.DomainModelCreators.allElementTypes
import static extension tools.vitruv.testutils.domains.DomainModelCreators.allElementTypes2
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.^extension.ExtendWith
import org.eclipse.xtext.testing.extensions.InjectionExtension
import org.eclipse.xtext.testing.InjectWith
import tools.vitruv.dsls.commonalities.tests.CommonalitiesLanguageInjectorProvider
import org.junit.jupiter.api.TestInstance
import javax.inject.Inject
import org.junit.jupiter.api.BeforeAll
import tools.vitruv.testutils.TestProject
import java.nio.file.Path
import static tools.vitruv.testutils.metamodels.AllElementTypesCreators.aet
import static tools.vitruv.testutils.metamodels.AllElementTypes2Creators.aet2
import static tools.vitruv.testutils.matchers.ModelMatchers.contains
import static tools.vitruv.testutils.matchers.ModelMatchers.ignoringFeatures
import tools.vitruv.testutils.VitruvApplicationTest
import tools.vitruv.dsls.commonalities.tests.util.TestCommonalitiesGenerator

@ExtendWith(InjectionExtension)
@InjectWith(CommonalitiesLanguageInjectorProvider)
@TestInstance(PER_CLASS)
@DisplayName('executing a commonality with attribute mapping operators')
class AttributeMappingOperatorExecutionTest extends VitruvApplicationTest {
	@Inject TestCommonalitiesGenerator generator
	
	@BeforeAll
	def void generate(@TestProject(variant = "commonalities") Path testProject) {
		generator.generate(testProject,
			'WithAttributeMappingOperators.commonality' -> '''
				import tools.vitruv.dsls.commonalities.tests.operators.multiply
				import tools.vitruv.dsls.commonalities.tests.operators.digits
				
				import "http://tools.vitruv.testutils.metamodels.allElementTypes" as AllElementTypes
				import "http://tools.vitruv.testutils.metamodels.allElementTypes2" as AllElementTypes2
				import "http://tools.vitruv.testutils.metamodels.pcm_mockup" as PcmMockup
				import "http://tools.vitruv.testutils.metamodels.uml_mockup" as UmlMockup
				
				concept operators
				
				commonality WithAttributeMappingOperators {
				
					with AllElementTypes:(Root in Resource)
					with AllElementTypes2:(Root2 in Resource)
				
					has id {
						= AllElementTypes:Root.id
						= AllElementTypes2:Root2.id2
						-> AllElementTypes:Resource.name
						-> AllElementTypes2:Resource.name
					}
				
					has number {
						// number <-> number mapping:
						= multiply(AllElementTypes:Root.singleValuedPrimitiveTypeEAttribute, 1000)
						= AllElementTypes2:Root2.singleValuedPrimitiveTypeEAttribute2
					}
				
					has numberList {
						// number <-> numberList mapping:
						= digits(AllElementTypes:Root.singleValuedEAttribute)
						= AllElementTypes2:Root2.multiValuedEAttribute2
					}
				}
			'''
		)
	}
	
	override protected getChangePropagationSpecifications() {
		generator.createChangePropagationSpecifications()
	}

	@Test
	@DisplayName('maps a simple attribute')
	def void singleToSingleValuedAttribute() {
		resourceAt('testid'.allElementTypes).propagate [
			contents += aet.Root => [
				id = 'testid'
				singleValuedPrimitiveTypeEAttribute = 123
			]
		]

		assertThat(resourceAt('testid'.allElementTypes), contains(aet.Root => [
			id = 'testid'
			singleValuedPrimitiveTypeEAttribute = 123
		]))
		assertThat(resourceAt('testid'.allElementTypes2), contains(aet2.Root2 => [
			id2 = 'testid'
			singleValuedPrimitiveTypeEAttribute2 = 123000
		], ignoringFeatures('multiValuedEAttribute2')))
	}

	// Value is divided by 1000 and rounded towards zero
	@Test
	@DisplayName('maps a simple attribute (reverse)')
	def void singleToSingleValuedAttributeReverse() {
		resourceAt('testid'.allElementTypes2).propagate [
			contents += aet2.Root2 => [
				id2 = 'testid'
				singleValuedPrimitiveTypeEAttribute2 = 123500
			]
		]

		assertThat(resourceAt('testid'.allElementTypes2), contains(aet2.Root2 => [
			id2 = 'testid'
			singleValuedPrimitiveTypeEAttribute2 = 123000
		]))
		assertThat(resourceAt('testid'.allElementTypes), contains(aet.Root => [
			id = 'testid'
			singleValuedPrimitiveTypeEAttribute = 123
		]))
	}

	@Test
{'fraction_non_alphanumeric': 0.09054163298302344, 'fraction_numerical': 0.01570620163991223, 'mean_word_length': 4.993079584775087, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, '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': '7327877', 'n_tokens_mistral': 3132, 'n_tokens_neox': 2612, 'n_words': 407}