Create test scenarios using a two-dimensional array

I am utilizing four arrays in creating various test cases, as demonstrated below:

var phone = ['phone1', 'phone2', 'phone3']; 
var browsers = ['chrome', 'firefox']; 
var location = ['1324','2434','4234','1234','3243']; 
var network = ['3g', '4g', 'wifi']; 
var isLogin = ['service worker', 'no service worker'];

I am struggling to write code that will generate 180 different test cases. I have attempted using for loops and recursion, but haven't found the perfect solution yet. Please note that I am working with JavaScript and can only use array for loop due to certain constraints.

If anyone could provide me with some inspiration or guidance, it would be greatly appreciated!

Answer №1

Exploring a scenario in Java involved using recursion, where the approach can also be applied to Javascript. The implementation entails working with 3 arrays, utilizing recursion for 2 of them.

public class Test3 {

    static String[] names = { "Ram", "Shyam", "Mohan", "Rohan", "Saket" };
    static String[] citys = { "Bhopal", "Indore", "Ujjan", "Dewas", "Rewa" };
    static String[] addresses = { "add1", "add2", "add3", "add4", "add5" };
    static StringBuffer buffer = new StringBuffer();

    public static void main(String... strings) {

        for (String name : names) {
            System.out.println(generateData(name)+"\n");
            buffer.setLength(0);
        }
    }

    public static String generateData(String name) {

        return createCombinations(name, 0, -1);
    }

    public static String createCombinations(String combination, int countA, int countB) {

        if ((countA == names.length - 1) && (countB == names.length - 1)) {

            return buffer.toString();

        }

        if (countB == addresses.length - 1) {
            countA++;
            countB = -1;
        }

        countB++;

        buffer.append(combination + citys[countA] + addresses[countB] + "\n");

        return createCombinations(combination, countA, countB);

    }

}

This solution aims to provide assistance!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Replace all occurrences of $regex in Node.js with the json data format

Here is a JSON example var json= { name: { '$regex': /^Amer$/i }, 'countries.name': { '$regex': /^UNited states$/i } } I am looking to reformat it using either lodash or string/json replace method to achieve the following st ...

Deleting an HTML column that has a dynamic header name <th> can be achieved by following these steps

I have a script that can add a new column to an HTML table. When the user clicks on add group, the header will change to Group1, Group2, and so on. I am currently adding a function for delete group that can delete all the added columns. The issue now is th ...

JavaScript function is not identifiable

I am currently developing a tic-tac-toe game with 9 buttons that will display either an X or O image depending on the boolean value of the variable isX. The main container for these buttons is a div element with the id 'stage' and each button ha ...

Adjusting color with the .on method in Event Listener

What's wrong with this code? html <!DOCTYPE html> <html> <head> <title>Ending Project</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> &l ...

Error occurred while executing 'npm start' command in ReactJS due to the module 'babel-code-frame' being unable to be located

Every time I attempt to run 'npm start' in the frontend of my application, the terminal spits out a massive error. My package.json file doesn't show any script errors, and I've deleted the 'node_modules' folder and reinstalle ...

Tips for preloading images in a Vue ProjectWould you like some guidance

I need a solution to preload all images on the page when the routing changes. Currently, the images I am using are stored locally and loading only when scrolling, which is not ideal. I want the images to be loaded on page mount rather than when scrolling ...

JavaScript - Dynamically Disable Select Option Elements Depending on the Selected Option

I'm currently working on a form that includes two select elements. Each of these select elements contains multiple options with corresponding values. The first select element, identified by the id "average," has five options while the second one, iden ...

Passing PHP Variables to Multiple Pages

I seem to be facing a bit of a challenge. I am successfully sending the variable c_prot to the page parsing.php. However, I also need to send this same variable to the page chart.php, but it doesn't quite work as expected. If you have encountered a si ...

Tips for resolving the error message 'Object(...) is not a function' when using ref().set() with Firebase

While attempting to include custom information for a newly registered user in Firebase, I encountered an issue where the ref().set() function is being identified as not a valid function. What could be causing this problem? I have verified that the syntax ...

Combining JSON Data with Fuzzy Matching

I have a JSON data structure that looks like this { "array": { "InvestmentsDeposits": { "NAME": "Investments & Deposits", "PARENT": [ { "CONTENT_ID": "Promotions", "DISP ...

Using a PhoneGap solution to establish communication with a remote database

Creating a phoneGap app that resembles Facebook, where users can post messages and receive comments from friends. The app is built on HTML, JS, and phoneGap and is connected to a MySQL database on a remote server. As a beginner, I am unsure how to pull and ...

Issue with Updating Selected Value in Dropdown List (SemanticUI)

For my dropdown list, I am utilizing SemanticUI <div class="ui dropdown"> <input type="hidden" name="gender"> <i class="dropdown icon"></i> <div class="default text">Gender</div> <div class="menu"> < ...

Steps for creating a button that increments by using ng loop:1. Begin

I am attempting to create a button that can be used to increment and decrement. However, I am facing an issue where all input fields are being affected instead of just one. This is the code in body.component.html <div class="items-detail-detail" *n ...

Retrieve information and update state right before component display in React Native

Consider this scenario: I have a modal that displays data from its state, which is an array. The state is set in the componentDidMount() function as recommended in the documentation. My goal is to display updated data every time the modal opens. I was able ...

Find similarities and differences between two CSV files

Dealing with 2 large files, both exceeding 1 million rows: The first file contains only an md5 hash The second file contains pairs of md5 and email addresses My task is to compare these two files and if the md5 hashes match, write the corresponding emai ...

Trouble with executing AJAX for API call

My current project is built on CI3 and I have created an API that belongs to a different domain than the application itself. $.ajax({ url: "http://www.example.com/restapi/index.php/api/user", type: "GET", data: {"user_id": user_id} ...

Adding AngularJS modules to an HTML file

Recently, I've been diving into the world of AngularJS, but I'm facing a roadblock - my HTML doesn't recognize the angular module I created. It's odd because the bindings work perfectly without involving the module... This is my HTML: ...

Tips for refining search outcomes from web scraping with Google App Script

My objective is to scrape data from the website : I am specifically interested in extracting the SP500 PE number, which currently stands at 39.57 (at the time of writing). I require this number to be formatted as 39,57, rather than 39.57. This is my curr ...

The mobile navigation in HTML has a slight issue with the ::after pseudo-element, specifically within the

As I prepare to launch my website, I have made adjustments to the mobile layout by moving the navigation links to a navigation drawer. The template I am using included JavaScript scripts to handle this navigation change. However, I encountered an issue whe ...

How can I instruct Babel to compile code for ES2021 compatibility?

My babel.config.js file looks like this: module.exports = function (api) { api.cache(true); return { "presets": [ "@babel/preset-react", [ "@babel/preset-env", ...