List Icon
Archive de la liste de diffusion

La liste de diffusion est fermée depuis juillet 2022, mais sert toujours d'archive d'informations sur QF-Test.
Cependant, si vous souhaitez rester informé des nouveautés concernant QF-Test, vous pouvez simplement vous abonner à la newsletter :
abonner à la newsletter 


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [QF-Test] Implementing Enum in scripting


  • Subject: Re: [QF-Test] Implementing Enum in scripting
  • From: "Tobias Lenz, QFS Support" <support@?.de>
  • Date: Fri, 14 Jul 2017 17:00:05 +0200
  • Delivered-to: qftest-list@?.net

Hello Kevin,

in Jython you can create a enum as showed in the following example:

class Denomination():
    den02 = 'den02'
    den05 = 'den05'
    den5 = 'den5'
    den10 = 'den10'
    def __init__(self, Type):
        self.value = Type

    def getDenomValue(self):
        if self.value == Denomination.den05:
            return 0.5
        if self.value == Denomination.den5:
            return 5.0
        if self.value == Denomination.den10:
            return 10.0
        if self.value == Denomination.den02:
            return 0.2

    def getDenomRowNum(self):
        if self.value == Denomination.den02:
            return 4
        if self.value == Denomination.den05:
            return 3
        if self.value == Denomination.den5:
            return 2
        if self.value == Denomination.den10:
            return 1

    def getNextDenom(self):
        if self.value == Denomination.den02:
            return Denomination(Denomination.den05)
        if self.value == Denomination.den05:
            return Denomination(Denomination.den5)
        if self.value == Denomination.den5:
            return Denomination(Denomination.den10)
        if self.value == Denomination.den10:
            return

    def __str__(self):
           return self.value

    def __eq__(self,y):
       return self.value==y.value

print Denomination.den02
d1 = Denomination(Denomination.den02)
d2 = Denomination(Denomination.den02)
print d1.getDenomRowNum()
print d1.getNextDenom().getDenomValue()


Groovy is much easier you can simply use the same java code:

enum Denomination {

	den02, den05, den5, den10;

	double getDenomValue() {
		switch (this) {
		case den05:
			return 0.5d;
		case den5:
			return 5.0d;
		case den10:
			return 10.0d;
		default:
			return 0.2d;
		}
	}

	// return the row number of the denomination in cash drawer table

		int getDenomRowNum() {
			switch (this) {
			case den10:
				return 1;
			case den5:
				return 2;
			case den05:
				return 3;
			default:
				return 4;
			}
		}

		Denomination getNextDenom() {
			switch (this) {
			case den02:
				return den05;
			case den05:
				return den5;
			case den5:
				return den10;
			default:
				return null;

		}
	}
}
d = Denomination.den5;
int num = d.getDenomRowNum();
println(num);



As groovy can interpret JavaCode as well.

Best regards

Tobias Lenz



Am 13.07.2017 um 03:13 schrieb Liu, Kevin (DPTI):
Hi,

I am very new to QF-Test and Jython and Groovy scripting language, and I
have a java class containing an Enum as follows:

public class CashDrawer {

private static enum Denomination {

                 den02, den05, den5,den10;

                 double getDenomValue(){

                                 switch(this) {

                                                 case den05:

                                                                 return
0.5d;

                                                 case den5:

                                                                 return
5.0d;

                                                 case den10:

                                                                 return
10.0d;

                                                 default:

                                                                 return
0.2d;

                                 }

                 }

                 //return the row number of the denomination in cash
drawer table

                 int getDenomRowNum() {

                                 switch(this) {

                                                 case den10:

                                                                 return 1;

                                                 case den5:

                                                                 return 2;

                                                 case den05:

                                                                 return 3;

                                                 default:

                                                                 return 4;

                                 }

                 }

                 Denomination getNextDenom() {

                                 switch(this) {

                                                 case den02:

                                                                 return
den05;

                                                 case den05:

                                                                 return
den5;

                                                 case den5:

                                                                 return
den10;

                                                 default:

                                                                 return
null;

                                 }

                 }

}

private Denomination currentDenom;

.

.

.

}

And I also had a look at the class CheckDataType at section 41.4.4 in
the manual, still haven’t got a clue on the implementation. Please give
me some example on how to write the above Enum in Jython or Groovy SUT
script.

Thanks in advance

Kevin



_______________________________________________
qftest-list mailing list
qftest-list@?.de
https://movement.qfs.de/mailman/listinfo/qftest-list

--
Get the most out of QF-Test - Support directly from the authors
* Training & consulting: www.qfs.de/en/qftest/training.html
* Phone & email support: www.qfs.de/en/qftest/support.html
_______________________________________________________________
Tobias Lenz

E: support@?.de
T: +49 8171 38648-20
F: +49 8171 38648-16

Quality First Software GmbH | www.qfs.de
Tulpenstr. 41 | 82538 Geretsried | Germany
GF Gregor Schmid, Dr. Martina Schmid, Karlheinz Kellerer
HRB München 140833