Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add equals method for workplans #316

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

marierin
Copy link

@marierin marierin commented Aug 3, 2023

  • override the equals-method to compare two workplans
  • compare the types of the steps
  • compare the connectors

still missing:

  • compare the parameters
  • compare not connected elements

feature for the ticket #242

@marierin marierin self-assigned this Aug 3, 2023
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@marierin marierin marked this pull request as draft August 3, 2023 12:09
}
Workplan newPlan = (Workplan)obj;

var start = this.Connectors.First(x => x.Name.Equals("Start"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can not do this based on names. This comparison needs to be more generic.

/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this into a static method on Workplan.Equals(workplanA, workplanB) instead of overwriting the object method.


if (!(isAlreadyChecked))
{
needToCheck.Add(follower);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the workplanstep id instead of collection index here.

- compare the types of steps and connectors
- create tests
@marierin marierin force-pushed the feature/addEqualsMethodForWorkplans branch from 98e2667 to 28eaa67 Compare August 4, 2023 06:56
List<IWorkplanStep> needToCheck = new List<IWorkplanStep>();
List<IWorkplanStep> newNeedToCheck = new List<IWorkplanStep>();

List<IWorkplanStep> check = new List<IWorkplanStep>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe checkED would be a better name


List<IWorkplanStep> check = new List<IWorkplanStep>();

needToCheck.Add(step);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be done together with the initialization `new List() {step};

{


for (int a = 0; a < step.Outputs.Length; a++)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be put in a separate method. You method is too long and unclear

var follower = this.Steps.FirstOrDefault(x => x.Inputs.Any(y => y.Equals(connector)));
var newFollower = newPlan.Steps.FirstOrDefault(x => x.Inputs.Any(y => y.Equals(newConnector)));

bool isAlreadyChecked = (check.Contains(follower) || check.Contains(newFollower));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you checking if newFollower is in check, when you only add steps of your current workplan to check?

{
var follower = this.Steps.FirstOrDefault(x => x.Inputs.Any(y => y.Equals(connector)));
var newFollower = newPlan.Steps.FirstOrDefault(x => x.Inputs.Any(y => y.Equals(newConnector)));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you check, if the outputs are the same?

@@ -14,6 +14,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Moryx.AbstractionLayer\Moryx.AbstractionLayer.csproj" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that fine or should the test move to Moryx.AbstractionLayer.Tests @1nf0rmagician ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either that or alternatively the test could be limited to IWorkplanStep and reflection.

[ActivityResults(typeof(DefaultActivityResult))]
public class AssemblingActivity : Activity<AssemblingParameters>
{

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove Empty lines

using Moryx.AbstractionLayer;
using Moryx.AbstractionLayer.Capabilities;
using System;
using System.Collections.Generic;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if all usings are needed

private Workplan fifthWorkplan;
private Workplan sixthWorkplan;

public Workplan CreateFirstWorkplan()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite a lot of duplicated code in the workplan creation

[TestFixture]
public class EqualTest
{
private Workplan firstWorkplan;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better names. What are the differences between each workplan?

/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj)
public static bool noteSameFollowringSteps(Workplan workplan, Workplan newWorkplan ,IWorkplanStep step, IWorkplanStep newStep, List<IWorkplanStep> needToCheck, List<IWorkplanStep> newNeedToCheck, List<IWorkplanStep> isChecked)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name is confusing. Methodnames are always written in PascalCase

using System.Linq;
using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you need this for?

- create an additional method to check connactions and following steps
- reduce unnecessary variables
- changing the sequence
- rename methods in the EqualTest class
- switch from a override method to a static method
@marierin marierin force-pushed the feature/addEqualsMethodForWorkplans branch from 8aadc89 to 2742aa4 Compare August 8, 2023 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants