int testParallel() { float resistors3[] = {3,3,3}; float resistors5[] = {100,100,100,100,100}; float resistors0[] = {0,1,10,100,1000}; // Test using big 'S' float totRes = calc_resistance(3,'P',resistors3); printf("Parallel = %7.2f\n",totRes); if (totRes != 1.0) { return 1; } // Test using small 'p' totRes = calc_resistance(3,'p',resistors3); printf("Parallel = %7.2f\n",totRes); if (totRes != 1.0) { return 1; } // Test using 5 resistors totRes = calc_resistance(5,'P',resistors5); printf("Parallel = %7.2f\n",totRes); if (totRes != 20.0) { return 1; } // Test with a 0ohm totRes = calc_resistance(5,'P',resistors0); printf("Parallel = %7.2f\n",totRes); if (totRes != 0) { return 1; } return 0; }
int testParallel() { float resistors[] = {1,1,1}; float totRes = calc_resistance(3,'P',resistors); printf("Parallel = %f\n",totRes); float resistors2[] = {3,3,3}; totRes = calc_resistance(3,'P',resistors2); printf("Parallel = %f\n",totRes); return 0; }
int main() { int count, i; float totRes; float *array; char conn; printf("Ange spänningskälla i V:"); printf("Ange koppling[S | P]:"); if (scanf("%c", &conn)!=1) { printf ("error - it is not an char\n"); return -1; } printf("Antal komponenter:"); if (scanf("%i", &count)!=1) { printf ("error - it is not an integer\n"); return -1; } array = (float*) malloc(sizeof(float) * count); for (i=0; i < count; i++) { printf("Komponent %d i ohm:",i + 1); if (scanf("%f", &array[i])!=1) { printf ("error - it is not an float\n"); return -1; } } // Calculate values printf("Ersättningsresistans: %.2f ohm\n",calc_resistance(count,conn,array)); printf("Effekt: %f W\n",1.78); printf("Ersättningsresistanser i E12-serien kopplade i serie:"); free(array); return 0; }
int testSerial() { float resistors[] = {1,2,3}; float totRes = calc_resistance(3,'S',resistors); printf("Serial = %f\n",totRes); return (totRes != 6.0); }
int testNull() { float totRes = calc_resistance(3,'P',NULL); if (totRes != -1) { return 1; } return 0; }
int testSerial() { float resistors[] = {1,2,3}; float resistors0[] = {0,1,10,100,1000}; // Test big 'S' float totRes = calc_resistance(3,'S',resistors); printf("Serial = %7.2f\n",totRes); if (totRes != 6.0) { return 1; } // Test small 's' totRes = calc_resistance(3,'s',resistors); printf("Serial = %7.2f\n",totRes); if (totRes != 6.0) { return 1; } // Test using 0 ohm totRes = calc_resistance(5,'s',resistors0); printf("Serial = %7.2f\n",totRes); if (totRes != 1111.0) { return 1; } return 0; }
/** * @brief Event method that is fired when it's time to calculate the output of the input * * Event method that fires when the button is clicked. This calculates the result of the electrolib functionality. * @return void **/ static void calculateAndPresentOutput(){ int RESISTANCEOUTPUTLABELROW = 6; int VOLTAGEOUTPUTLABELROW = 7; int E12OUTPUTLABELROW = 8; float* replaceResistanceValues = calloc(3,sizeof(float)); float totalresistance = calc_resistance(getNumberOfComponents(), getConnectionType(), getResistanceItems()); float totalpower = calc_power_r(getVoltage(), totalresistance); int numberOfResistors = e_resistance(totalresistance, replaceResistanceValues); char formatedMessage[100]; sprintf(formatedMessage, "Ersättningsresistance: %.1f ohm", totalresistance); addOutputLabel(_mainGrid, formatedMessage, 1, RESISTANCEOUTPUTLABELROW, 2); sprintf(formatedMessage, "Effekt: %.2f W", totalpower); addOutputLabel(_mainGrid, formatedMessage, 1, VOLTAGEOUTPUTLABELROW, 2); sprintf(formatedMessage, "Ersättningsresistans i E12-serien koppliade i serie: %.0f, %.0f, %.0f", *replaceResistanceValues, *(replaceResistanceValues+1), *(replaceResistanceValues+2)); addOutputLabel(_mainGrid, formatedMessage, 1, E12OUTPUTLABELROW, 2); }
int main() { int count, i; float totRes; float volt=2.0; float power; float *array; char conn; float resistors[3]; float *fp=&resistors[0]; int antal; printf("Ange koppling[S | P]: "); if (scanf("%c", &conn)!=1) { printf ("Error - Inmatat värde är inte en char\n"); return -1; } printf("Antal komponenter: "); if (scanf("%i", &count)!=1) { printf ("Error - Inmatat värde är inte en integer\n"); return -1; } array = (float*) malloc(sizeof(float) * count); for (i=0; i < count; i++) { printf("Komponent %d i ohm: ",i + 1); if (scanf("%f", &array[i])!=1) { printf ("Error - Inmatat värde är inte en float\n"); return -1; } } // Calculate values totRes = calc_resistance(count,conn,array); if (totRes == -1) {printf ("Error - Misslyckades med att räkna ut ersättningsresistans\n"); return -1;} printf("Ersättningsresistans: %.2f ohm\n",totRes); printf("Ange spänningskälla i V: "); if (scanf("%f", &volt)!=1){ printf("Error - Inmatat värde är inte en float\n"); return -1;} power = calc_power_r(volt, totRes); printf("Effekt: %.2f W\n", power); printf("Ersättningsresistanser i E12-serien kopplade i serie: "); for (antal = e_resistance(totRes, &resistors[0]); antal>0; antal--){ printf("%1.0f", *fp++); if (antal>1) printf(", "); } printf("\n"); free(array); return 0; }
int main(void) { char koppling; int antal; float *komp; int i = 0; printf("Ange koppling[S | P]:"); scanf("%c", &koppling); printf("Antal komponenter:"); scanf("%d", &antal); komp = (float*)malloc(sizeof(float)*antal); for(i=0; i<antal; i++) { printf("Komponent %d i ohm:", i+1); scanf("%f", &komp[i]); } printf("Ersättningsresistans: %f ohm \n", calc_resistance(antal, koppling, komp)); return 0; }