two_sum_testcode

#include <stdlib.h>
#include <stdio.h>

typedef struct node{
    struct node* next;
    int data;
    int arry_i;
}node_t;

void insert_list_head(int data,int i,node_t **head_addr){
    node_t *p=(node_t*)malloc(sizeof(node_t));
    if(*head_addr==NULL)
    {
        p->next=NULL;
    }
    else
    {
        p->next=*head_addr;
    }
    p->data=data;
    p->arry_i=i;
    *head_addr=p;
}


void creat_hash_tab(int A[10],node_t* hash_arr[4],int hash_key){
    int hash_index,i,n;
    for(i=0;i<4;i++)
    {
        hash_arr[i]=NULL;
    }
    for(n=0;n<10;n++)
    {
        if(A[n]<hash_key)
        {
            insert_list_head(A[n],n,&hash_arr[0]);
        }
        else
        {
            hash_index=(A[n]%hash_key)+1;
            insert_list_head(A[n],n,&hash_arr[hash_index]);
        }
    }

}

/******************************************
void display_hash_tab(node_t* hash_arr[])
{
    int i;
    for(i=0;i<4;i++)
{
    node_t* p=hash_arr[i];
    printf("line %d--->",i);
    while(p!=NULL)
    {
        printf("%d->",p->data);
        p=p->next;
    }
    printf("null\n");
}
}
******************************************/

node_t* search_list(node_t* hash_arry[],int hash_arry_index,int search_val,node_t* search_start){
    node_t* p=search_start;
    if(p!=NULL)
    {
        while(p!=NULL){
            if(p->data==search_val)
            {
                return p;
            }
            else
            {
                p=p->next;
            }
        }
    }
    else{
        p=hash_arry[hash_arry_index];
        while(p!=NULL){
            if(p->data==search_val)
            {
                return p;
            }
            else
            {
                p=p->next;
            }
        }
    }
    return NULL;
}

int* twoSum(node_t* nums[], int numsSize, int target){
    int result[numsSize];
    node_t* ret=NULL;
    node_t* p;
    int *p_1;
    int hash_index,i,target_rest;
    for(i=0;i<4;i++)
    {
        p=nums[i];
        while(p!=NULL){
            target_rest=target-p->data;
            if(target_rest<3){
                hash_index=0;
            }
            else{
                hash_index=(target_rest%3)+1;
            }
            if(hash_index==i){
                ret=search_list(nums,hash_index,target_rest,p->next);
            }
            else{
               ret=search_list(nums,hash_index,target_rest,NULL);
            }
            if(ret!=NULL){
                result[0]=p->arry_i;
                result[1]=ret->arry_i;
                p_1=result;
                return p_1;
            }
            p=p->next;
        }

    }
    return NULL;
}

void main(){
    int A[10]={1,2,3,4,5,6,7,8,9,11};
    node_t* hash_arr[4];
    creat_hash_tab(A,hash_arr,3);
//    display_hash_tab(hash_arr);
    int*ret;
    ret=twoSum(hash_arr, 2, 9);
    printf("[%d,%d]\n",ret[0],ret[1]);
}

===========================================

[root@test1 ~]# gcc -g hash.c -o hash
[root@test1 ~]# ./hash
[1,6]


Certainly! Here's an example of how you can use the `@after_step` hook in pytest-bdd to perform actions after each step in your BDD scenarios. ```python import pytest from pytest_bdd import scenario, given, when, then, after_step @scenario('demo.feature', 'Add two numbers') def test_add_numbers(): pass @given("I have two numbers <a> and <b>") def numbers(a, b): return int(a), int(b) @when("I add the numbers") def add_numbers(numbers): return sum(numbers) @then("I expect the result <result>") def expect_result(add_numbers, result): assert add_numbers == int(result) @after_step def take_screenshot(request): # Code to take a screenshot after each step # Replace this with your own implementation if request.node.rep_call.failed: # Take a screenshot only if the step failed # You can use any screenshot library or code here print("Taking a screenshot") # You can define multiple after_step hooks if needed @after_step def log_step(request): # Code to log the step details after each step # Replace this with your own implementation print(f"Step '{request.node.name}' finished") ``` In this example, we define two `@after_step` hooks. The first `take_screenshot` hook takes a screenshot after each step if the step failed. You can replace the placeholder code with your own implementation to capture screenshots. The second `log_step` hook logs the details of each step after it finishes. You can replace the placeholder code with your own logging logic. To run the tests and see the `@after_step` hooks in action, execute `pytest` in your terminal. Note that the `@after_step` hook is executed after each step, regardless of whether the step passed or failed. You can use it to perform various actions such as logging, capturing screenshots, cleaning up resources, etc., based on your testing requirements.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值