Software testing/test Development, pair programming assistant GitHubCopilot

Time:2024-1-25

Click here for more information

summary

GitHub Copilot is an AI twinning programmer that helps you write code faster and with less effort.GitHub Copilot is powered by generative AI models developed by GitHub, OpenAI, and Microsoft. It is available as an extension to the Visual Studio Code, Visual Studio, Neovim, and JetBrains integrated development environment (IDE) suites.

How to use

environmental preparation
  • Scientific Internet access: A network environment with smooth access to the GitHub website.
  • IDE: Supports integrated development environments such as JetBrains IDEs, Visual Studio, and more.
Environment Installation

1. Go to the official website GitHub-Copilot registration information.

2. GitHub-Copilot costs $10 a month, and you need to fill out your credit card information first, but you can try it for free for 30 days, so you can cancel the renewal before the 30 days are up.

Software testing/test Development, pair programming assistant GitHubCopilot

3. Fill in the credit card information accurately and click Submit to finish.

Software testing/test Development, pair programming assistant GitHubCopilot

4. Open the IDE, take Pycharm as an example, open Settings -> Plugins -> Marketplace, search for GitHub Copilot, click Install and wait for the installation to complete and click Restart IDE.

Software testing/test Development, pair programming assistant GitHubCopilot

5. After installing the plugin, log in Pycharm, click Tools -> GitHub Copilot -> Login to GitHub.

Software testing/test Development, pair programming assistant GitHubCopilot

6. Click Copy and Open, click the verification code to paste it into the pop-up browser, click Continue and then click Authorize Authorize GitHub Copilot Plugin.

Software testing/test Development, pair programming assistant GitHubCopilot

7. Wait for Pycharm to load and then you can use GitHub Copilot.

Software testing/test Development, pair programming assistant GitHubCopilot

hands-on exercise

Instructions for use

1. In the status bar at the bottom right of PyCharm, the red circle indicates the GitHub Copilot logo, which means that the GitHub Copilot plugin is enabled.

2. Whether you’re writing a comment in your code, or executing a line of code, or a block of code, or a function, GitHub Copilot will continue to provide code-completion suggestions as you type.

caveat

1. GitHub Copilot may also guess the wrong code you intend to write, but as long as you keep typing, it will give new suggestions.

2. For any given input, GitHub Copilot may provide multiple suggestions. You can choose which suggestions to use, or reject all of them, depending on your needs.

3. Users can enable or disable GitHub Copilot: Click the status icon in the status bar at the bottom right of PyCharm to select the suggestion to enable or disable GitHub Copilot.

Related Shortcuts
OSView Next SuggestionView previous suggestionReceiving recommendationsRejection of recommendationsDisplay Recommendations
macOScommand+]command+[tabescoption+
WindowsAlt+]Alt+[tabescalt+
LinuxAlt+]Alt+[tabescalt+
Writing a Quick Sort with Copilot
  1. Enter the relevant comment as well as the beginning.

    Software testing/test Development, pair programming assistant GitHubCopilot

2. It will automatically start to complete the code. The gray part is the code it suggests, click tab to receive its suggestions.

Merge two lists and sort them

1. Enter notes and requirements:

Merge two lists and sort them

2. According to the needs of the prompt, has been pressing the tab key, the middle will automatically generate comments as well as the realization of the code, all of the following code is automatically generated:

def merge_list(list1, list2):
 # Merge two lists and sort them
 # 1. Define two pointers to the first element of two lists.
 p1 = 0
 p2 = 0
 # 2. Define a new list to store the results of the merge
 result = []
 # 3. Loop over the elements pointed to by the two pointers and add the smaller element to the new list
 while p1 < len(list1) and p2 < len(list2):
     if list1[p1] < list2[p2]:
         result.append(list1[p1])
         p1 += 1
     else:
         result.append(list2[p2])
         p2 += 1
 # 4. add elements from the uncompared list to the new list
 result += list1[p1:]
 result += list2[p2:]
 # 5. Return to new list
 return result

3. Write a unit test case to test whether it is realized, write a function nameddef test_merge_list():, other than using auto-completion, the final unit test case generated results in:

def test_merge_list():
   assert merge_list([1,2,5], [3,4,6]) == [1,2,3,4,5,6]

summarize

1. Copilot’s environment is very simple to install and use, you can think of it as a ChatGPT used in an IDE.

2. Some explicit code logic can be given to it to accomplish.

3. Not all outputs from Copilot are correct and need to be corrected appropriately during use.

Recommended Today

DML statements in SQL

preamble Previously we have explained DDL statements in SQL statements. Today we will continue with the DML statement of SQL. DML is the Data Manipulation Language.Used to add, delete, and change data operations on the tables in the library.。 1. Add data to the specified field(INSERT) 2. Modify data(UPDATE) 3. Delete data(DELETE) catalogs preamble I. […]