#I don't understand the concept of Abstract Test Class?

65 messages · Page 1 of 1 (latest)

floral parcel
#

I have implemented different variations of quicksort method, where each variation extends a class called IntSort. The abstract class is IntSortTest, and I will need to implement Test Classes for each variation. But let's focus on one for now. since I don't even know where to begin. From the instruction and given the skeleton code I got this is how I think the IntSortTest abstract class should look like: ```java

public abstract class IntSorterTest {

 protected abstract IntSorter getIntSorter();
 private Data evenArray = new Data (100, 100, Data.Order.RANDOM);
 private Data oddArray = new Data (99, 99, Data.Order.RANDOM);
 private Data ascendingArray = new Data (100, 99, Data.Order.ASCENDING);
 private Data descendingArray = new Data (100, 99, Data.Order.DESCENDING);
 private Data sameElemArray = new Data (10, 1, Data.Order.RANDOM);





 @Before
 public void setUp() {
 }


@Test
public void sortEvenArraysWillGiveASortedArray(){
    int [] expected = evenArray.get();
    int [] actual = evenArray.get();
    getIntSorter().sort(actual);
    Arrays.sort(expected);
    // Assert
    assertArrayEquals(actual, expected);}

    @Test
public void sortOddArraysWillGiveASortedArray(){
    int [] expected = oddArray.get();
    int [] actual = evenArray.get();
    getIntSorter().sort(actual);
    Arrays.sort(expected);
        // Assert
    assertArrayEquals(actual, expected);}

}

I have a class called "QuickSortFixedPivot" and how should I implement it's test class? What method should it contain? Also is my implementation of IntSort even
devout wadiBOT
#

This post has been reserved for your question.

Hey @floral parcel! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

raven hare
#

Typically when you need to use an abstract class, you need to create another class that extends it.
Whenever you extend an abstract class, it will require that you provide an implementation for its abstract methods

#

Here the abstract method is getIntSorter() that returns an IntSorter

#

So you'd need to provide a getIntSorter() method that returns an instance of QuickSortFixedPivot

#

And normally everything inherited from the abstract class does the rest of the job of testing it

sonic orchid
#

Hi @floral parcel and Kyo-Chan, I’m Alexander Lill (a real person), a researcher at the University of Zurich. I’m trying to help people receive answers faster on Discord. If you are not ok with giving me some feedback, click the 🚪 symbol, and I will delete this message and apologize for the inconvenience.

#

Would any of the provided links have helped to answer the OPs question? Please click the number-emoji for each link that would have been helpful, and on the ❌ if none of the links would have been helpful to answer the OPs question.

1️⃣ CompareTest - Is it Possible to Run Just the CompareTest?
<#help-cubano message>

2️⃣ Java Public Abstract Class Element Private Double Schmelzpunkt
<#help-americano message>

3️⃣ ToString() ToString(Int Depth)
<#help-medici message>

Let me know if you have any questions! More info: #announcements message

raven hare
sonic orchid
#

Hey 🙂 I am using a word embedding that tries to find similar questions to the OPs question

raven hare
#

That doesn't sound like a real person is doing it

sonic orchid
#

I am still posting it 🙂

raven hare
#

My point is, it sounds like you're lying when you post

sonic orchid
#

Yes that's a known problem, probably because I use a template and need some boilerplate to inform people about the study, it would be better to just post the links without any of the disclaimers. Unfortunately they are needed for the study

raven hare
#

Or the disclaimers could say that a real person was not involved in the process

sonic orchid
#

But I am a real person posting the suggestions. I am not an automated bot

#

A real person is involved in the process

raven hare
#

You sound dishonest to me. I have raised my concerned about that fact, and I suppose I am not interested in further discussing the issue.

sonic orchid
#

Okay, thanks for your feedback in any case!

floral parcel
#

BTW I have been googling a lot, I even checked a java book my prof recommened us, I searched on youtube. There is basically no information about abstract Test class. It was my understanding that an abstact class is like "Animal". The concept of animal is abstract, but all animals do similar things different ways. The abstact method's don't get implemented in the abstract class but when it comes to Test Class, methods are implemented so I was wondering if Test Class don't follow the same rules or if I am totally wrong about abstract class'?

raven hare
#

IntSorter is supposed to be the supertype of all your sort algorithms

#

That's why there is a need of a getIntSorter() method to provide what algirithm to use

#

The functional rules about how abstract classes work still apply with test classes (except that the abstract class doesn't particularly need to end its name with Test as it can't be run as a test all by itself).
It's just the general idea of what abstract classes are supposed to be from a conceptual point of view, is lost in this situation, to leverage the practicality of polymorphism and inheritance rather than the proper OOP designs

floral parcel
#

Obviously this is not correct since I this is full of errors but I don't know what I doing wrong?

raven hare
#

The test classes dont implement IntSorter, the test classes test the classes thzt implement TestSorter

#

And yes the test classes eaxh need to have that method, that return an instance of your sort algorithm, that must be a subtype of IntSorter

floral parcel
#

is my implementation of the method correct? Is this what you meant earlier?

raven hare
#

No you must return your algorithm

#

If you want to test SelectionSort you must return something like new SelectionSort()

floral parcel
raven hare
#

Except that's not how you create a new object. But it gets close to the idea

#

You've never used new ?

floral parcel
#
   protected IntSorter getIntSorter(){
    QuicksortFixedPivot quick = new QuicksortFixedPivot();
    return  quick;
}```
#

Again why do I need to do this?

#

Also if you see in the question, I already implemented some test methods (plenty but only posted some of them) that should work for all the class that extends IntSorterTest. So my question is what methods do I implement for example here?

raven hare
#

You need to do that so that the test class uses this sort algorithm when it runs its tests

floral parcel
raven hare
#

Yes. Because the test methods call getIntSort() to get the algorithm to sort with

floral parcel
#

Alright

#

So now what is left for me to understand in order to move forward is the difference between the abstract test class and the test class that extends it.

#

I mean what type of test methods do I need to implement in for example "QuicksortFixedPivot"

#

You don't need to give me exact answer, just what is the main point of this test class is.

raven hare
#

You do not need to implement test methods. The abstract test class has them

floral parcel
#

So is this like done but, the abstract test class is not working. I can't even press it, like run it.

#

no wait

#

you're right

#

It is working, some methods passed already

raven hare
#

It is abstract. You can't use it directlt, you need to extend it

floral parcel
raven hare
#

Unfirtunately what I learned with is long gone.

floral parcel
#

So again just to make SURE, I don't need to implement any methods in the other test class' that extends IntSorter?

raven hare
#

Test classes dont extend IntSorter so I'm not sure what to tell you

floral parcel
#

I mean IntSorterTest

#

Because in the past assignments, both test class that extends an abstract test class, and the abstract test class had test methods. I didn't implement them tho, they were given.

raven hare
#

Then yes, there are already test methods and there is no absolute needs for more. I suppose you.may want to try adding more in IntSorterTest

raven hare
#

If you happen to have specific things to test for a sort algorithm, you may add test methods in its test class too

floral parcel
devout wadiBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

sonic orchid
#

Hey @floral parcel, did you by any chance check out my links? Were any of them relevant?