简体   繁体   English

如何在 Beanshell 中将一个数组值与其他数组值相关联

[英]How to relate one array values with other in Beanshell

I have a scenario where I have arrays like Names(Mike, Harry, Jones, Jack, Jimmy) Rank(4,2,1,3,5) and Rollno(S12,S76,S89,S87,S99).我有一个场景,我有像 Names(Mike, Harry, Jones, Jack, Jimmy) Rank(4,2,1,3,5) 和 Rollno(S12,S76,S89,S87,S99) 这样的数组。 I need to capture lowest rank and associated name and roll no in beanshell.我需要在 beanshell 中捕获最低等级和相关名称并拒绝。

I'm expecting to capture lowest rank and to get their names and roll no.我期待获得最低排名并获得他们的名字和投票号码。

Since JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting so I will provide solution in Groovy : 从 JMeter 3.1 开始,您应该使用 JSR223 测试元素和 Groovy 语言编写脚本,因此我将在Groovy中提供解决方案:

import java.util.stream.IntStream

def Names = ['Mike', 'Harry', 'Jones', 'Jack', 'Jimmy']
def Rank = [4, 2, 1, 3, 5]
def Rollno = ['S12', 'S76', 'S89', 'S87', 'S99']

def lowestRankIndex = IntStream
        .range(0, Rank.size())
        .reduce((i, j) -> Rank.get(i) > Rank.get(j) ? j : i)
        .getAsInt()

def lowestRankName = Names.get(lowestRankIndex)

def lowestRankRollno = Rollno.get(lowestRankIndex)

log.info('Lowest rank name: ' + lowestRankName + ' rollno: ' + lowestRankRollno)

Demo:演示:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM