Skip to content

Conversation

@franzxschmid
Copy link

No description provided.


public boolean add(T t) {
return false;
Object[] newElements = new Object[++this.length];
Copy link
Owner

Choose a reason for hiding this comment

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

Ein kleiner Grundsatzgedanke, den man immer im Hinterkopf behalten sollte: Die interne Datenstruktur weg-abstrahieren.

Es gibt hier eine Funktion für die Länge, nämlich size(). Es macht absolut Sinn, auch intern mit den selben Methoden zu arbeiten. Das macht späteres Refactoring deutlich einfacher!

return false;
Iterator<?> iterator = c.iterator();
for (int i = 0; i < c.size(); i++) {
if (this.contains(iterator.next())) {
Copy link
Owner

Choose a reason for hiding this comment

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

Wenn du mit einem iterator arbeitest, kannst du auch immer while (iterator.hasNext()) machen!

return false;
Iterator<?> iterator = c.iterator();
for (int i = 0; i < c.size(); i++) {
this.add((T) iterator.next());
Copy link
Owner

Choose a reason for hiding this comment

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

Hier auch. Iterator lässt sich gut mit while() kombinieren!


public void clear() {

this.elements = new Object[0];
Copy link
Owner

Choose a reason for hiding this comment

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

Es macht evtl. Sinn, hier mit null oder einem private static final EMPTY object zu arbeiten.


public class MyListImplementation<T> implements MyList<T> {

private Object[] elements;
Copy link
Owner

Choose a reason for hiding this comment

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

Object ist natürlich nicht so ideal. Es soll doch ein T sein


import static org.assertj.core.api.Assertions.assertThat;

public class MyListImplementationTest {
Copy link
Owner

Choose a reason for hiding this comment

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

Versuch dich nächstes mal an das pattern with...should für Testnamen zu halten. Das macht es ein bisschen lesbarer, was die Tests aussagen sollen

MyListImplementation list = new MyListImplementation<Integer>();
list.add(1);
list.add(2);
assertThat(list.contains(1)).isEqualTo(true);
Copy link
Owner

Choose a reason for hiding this comment

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

Gerne in 2 Testfälle spalten. Einen Positiv-Test und einen Negativ-Test.

Das wären dann:
withListContainingValue_shouldReturnTrue
withListNotContainingValue_shouldReturnFalse

Grundsätzlich eine "fachlichkeit" pro Testfall!

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.

2 participants